mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 04:17:46 +02:00
remove several export env usage in test code
This commit is contained in:
@ -54,14 +54,6 @@ impl Command for Module {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define an environment variable in a module and evaluate it",
|
||||
example: r#"module foo { export env FOO_ENV { "BAZ" } }; use foo FOO_ENV; $env.FOO_ENV"#,
|
||||
result: Some(Value::String {
|
||||
val: "BAZ".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define a custom command that participates in the environment in a module and call it",
|
||||
example: r#"module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
|
||||
|
@ -125,7 +125,7 @@ impl Command for OverlayHide {
|
||||
},
|
||||
Example {
|
||||
description: "Hide the last activated overlay",
|
||||
example: r#"module spam { export env FOO { "foo" } }
|
||||
example: r#"module spam { export-env { let-env FOO = "foo" } }
|
||||
overlay use spam
|
||||
overlay hide"#,
|
||||
result: None,
|
||||
|
@ -199,7 +199,7 @@ impl Command for OverlayUse {
|
||||
},
|
||||
Example {
|
||||
description: "Create an overlay from a file",
|
||||
example: r#"echo 'export env FOO { "foo" }' | save spam.nu
|
||||
example: r#"echo 'export-env { let-env FOO = "foo" }' | save spam.nu
|
||||
overlay use spam.nu
|
||||
$env.FOO"#,
|
||||
result: None,
|
||||
|
@ -145,14 +145,6 @@ impl Command for Use {
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define an environment variable in a module and evaluate it",
|
||||
example: r#"module foo { export env FOO_ENV { "BAZ" } }; use foo FOO_ENV; $env.FOO_ENV"#,
|
||||
result: Some(Value::String {
|
||||
val: "BAZ".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Define a custom command that participates in the environment in a module and call it",
|
||||
example: r#"module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#,
|
||||
|
@ -189,9 +189,9 @@ impl Command for ViewSource {
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a module",
|
||||
example: r#"module mod-foo { export env FOO_ENV { 'BAZ' } }; view-source mod-foo"#,
|
||||
example: r#"module mod-foo { export-env { let-env FOO_ENV = 'BAZ' } }; view-source mod-foo"#,
|
||||
result: Some(Value::String {
|
||||
val: " export env FOO_ENV { 'BAZ' }".to_string(),
|
||||
val: " export-env { let-env FOO_ENV = 'BAZ' }".to_string(),
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
},
|
||||
|
@ -230,7 +230,7 @@ fn parse_module_success_2() {
|
||||
r#"
|
||||
# foo.nu
|
||||
|
||||
export env MYNAME { "Arthur, King of the Britons" }
|
||||
export-env { let-env MYNAME = "Arthur, King of the Britons" }
|
||||
"#,
|
||||
)]);
|
||||
|
||||
|
@ -1084,94 +1084,6 @@ pub fn parse_export_in_module(
|
||||
|
||||
exportables
|
||||
}
|
||||
b"env" => {
|
||||
if let Some(id) = working_set.find_decl(b"export env", &Type::Any) {
|
||||
call.decl_id = id;
|
||||
} else {
|
||||
return (
|
||||
garbage_pipeline(spans),
|
||||
vec![],
|
||||
Some(ParseError::InternalError(
|
||||
"missing 'export env' command".into(),
|
||||
export_span,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
let sig = working_set.get_decl(call.decl_id);
|
||||
let call_signature = sig.signature().call_signature();
|
||||
|
||||
call.head = span(&spans[0..=1]);
|
||||
|
||||
let mut result = vec![];
|
||||
|
||||
if let Some(name_span) = spans.get(2) {
|
||||
let (name_expr, err) =
|
||||
parse_string(working_set, *name_span, expand_aliases_denylist);
|
||||
error = error.or(err);
|
||||
call.add_positional(name_expr);
|
||||
|
||||
let env_var_name = working_set.get_span_contents(*name_span).to_vec();
|
||||
|
||||
if let Some(block_span) = spans.get(3) {
|
||||
let (block_expr, err) = parse_block_expression(
|
||||
working_set,
|
||||
&SyntaxShape::Block(None),
|
||||
*block_span,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
error = error.or(err);
|
||||
|
||||
if let Expression {
|
||||
expr: Expr::Block(block_id),
|
||||
..
|
||||
} = block_expr
|
||||
{
|
||||
result.push(Exportable::EnvVar {
|
||||
name: env_var_name,
|
||||
id: block_id,
|
||||
});
|
||||
} else {
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::InternalError(
|
||||
"block was not parsed as a block".into(),
|
||||
*block_span,
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
call.add_positional(block_expr);
|
||||
} else {
|
||||
let err_span = Span {
|
||||
start: name_span.end,
|
||||
end: name_span.end,
|
||||
};
|
||||
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::MissingPositional(
|
||||
"block".into(),
|
||||
err_span,
|
||||
call_signature,
|
||||
))
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let err_span = Span {
|
||||
start: kw_span.end,
|
||||
end: kw_span.end,
|
||||
};
|
||||
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::MissingPositional(
|
||||
"environment variable name".into(),
|
||||
err_span,
|
||||
call_signature,
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
_ => {
|
||||
error = error.or_else(|| {
|
||||
Some(ParseError::Expected(
|
||||
@ -1336,7 +1248,6 @@ pub fn parse_module_block(
|
||||
error = error.or(err);
|
||||
|
||||
for pipeline in &output.block {
|
||||
// TODO: Should we add export env predecls as well?
|
||||
if pipeline.commands.len() == 1 {
|
||||
parse_def_predecl(
|
||||
working_set,
|
||||
|
Reference in New Issue
Block a user