mirror of
https://github.com/nushell/nushell.git
synced 2024-11-29 03:44:19 +01:00
Support multiple shorthand env vars (#3692)
This commit is contained in:
parent
a2dc4199d0
commit
0c82c1920e
@ -2099,18 +2099,33 @@ pub fn classify_block(
|
|||||||
for group in &lite_block.block {
|
for group in &lite_block.block {
|
||||||
let mut out_group = Group::basic();
|
let mut out_group = Group::basic();
|
||||||
for pipeline in &group.pipelines {
|
for pipeline in &group.pipelines {
|
||||||
let (pipeline, vars, err) = expand_shorthand_forms(pipeline);
|
let mut env_vars = vec![];
|
||||||
|
let mut pipeline = pipeline.clone();
|
||||||
|
loop {
|
||||||
|
if pipeline.commands.is_empty() || pipeline.commands[0].parts.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let (pl, vars, err) = expand_shorthand_forms(&pipeline);
|
||||||
if error.is_none() {
|
if error.is_none() {
|
||||||
error = err;
|
error = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (out_pipe, err) = parse_pipeline(pipeline.clone(), scope);
|
pipeline = pl;
|
||||||
|
if let Some(vars) = vars {
|
||||||
|
env_vars.push(vars);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pipeline_span = pipeline.span();
|
||||||
|
let (mut out_pipe, err) = parse_pipeline(pipeline, scope);
|
||||||
if error.is_none() {
|
if error.is_none() {
|
||||||
error = err;
|
error = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pipeline = if let Some(vars) = vars {
|
while let Some(vars) = env_vars.pop() {
|
||||||
let span = pipeline.span();
|
let span = pipeline_span;
|
||||||
let block = hir::Block::new(
|
let block = hir::Block::new(
|
||||||
Signature::new("<block>"),
|
Signature::new("<block>"),
|
||||||
vec![Group::new(vec![out_pipe.clone()], span)],
|
vec![Group::new(vec![out_pipe.clone()], span)],
|
||||||
@ -2149,16 +2164,14 @@ pub fn classify_block(
|
|||||||
args: call,
|
args: call,
|
||||||
});
|
});
|
||||||
|
|
||||||
Pipeline {
|
out_pipe = Pipeline {
|
||||||
list: vec![classified_with_env],
|
list: vec![classified_with_env],
|
||||||
span,
|
span,
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out_pipe
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if !pipeline.list.is_empty() {
|
if !out_pipe.list.is_empty() {
|
||||||
out_group.push(pipeline);
|
out_group.push(out_pipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !out_group.pipelines.is_empty() {
|
if !out_group.pipelines.is_empty() {
|
||||||
|
@ -6,6 +6,22 @@ use nu_test_support::playground::Playground;
|
|||||||
|
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn env_shorthand() {
|
||||||
|
let actual = nu!(cwd: ".", r#"
|
||||||
|
FOO=bar echo $nu.env.FOO
|
||||||
|
"#);
|
||||||
|
assert_eq!(actual.out, "bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn env_shorthand_multi() {
|
||||||
|
let actual = nu!(cwd: ".", r#"
|
||||||
|
FOO=bar BAR=baz $nu.env.FOO + $nu.env.BAR
|
||||||
|
"#);
|
||||||
|
assert_eq!(actual.out, "barbaz");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn passes_let_env_env_var_to_external_process() {
|
fn passes_let_env_env_var_to_external_process() {
|
||||||
let actual = nu!(cwd: ".", r#"
|
let actual = nu!(cwd: ".", r#"
|
||||||
|
Loading…
Reference in New Issue
Block a user