From f29dbeddd7d9040898d10b892badd8fc39db0967 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:19:13 -0500 Subject: [PATCH] Allow let-env to be dynamic (#940) --- crates/nu-command/src/env/let_env.rs | 6 ++---- src/tests/test_engine.rs | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/env/let_env.rs b/crates/nu-command/src/env/let_env.rs index 829abf1cc1..4035959cca 100644 --- a/crates/nu-command/src/env/let_env.rs +++ b/crates/nu-command/src/env/let_env.rs @@ -1,4 +1,4 @@ -use nu_engine::{current_dir, eval_expression_with_input}; +use nu_engine::{current_dir, eval_expression_with_input, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{Category, PipelineData, Signature, SyntaxShape, Value}; @@ -33,9 +33,7 @@ impl Command for LetEnv { call: &Call, input: PipelineData, ) -> Result { - let env_var = call.positional[0] - .as_string() - .expect("internal error: missing variable"); + let env_var = call.req(engine_state, stack, 0)?; let keyword_expr = call.positional[1] .as_keyword() diff --git a/src/tests/test_engine.rs b/src/tests/test_engine.rs index aae132b880..eb38281600 100644 --- a/src/tests/test_engine.rs +++ b/src/tests/test_engine.rs @@ -230,3 +230,8 @@ fn export_def_env() -> TestResult { "BAZ", ) } + +#[test] +fn dynamic_let_env() -> TestResult { + run_test(r#"let x = "FOO"; let-env $x = "BAZ"; $env.FOO"#, "BAZ") +}