From 4d7d97e0e6a0c1df0d67dc0a798390d4d695f872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 10 Dec 2022 19:23:55 +0200 Subject: [PATCH] Simplify FILE_PWD setting in 'overlay use' (#7425) # Description Changes the `FILE_PWD` setting mechanism to match the one used in the `use` command. Fixes https://github.com/nushell/nushell/pull/7424 # User-Facing Changes None # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- crates/nu-command/src/core_commands/overlay/use_.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/nu-command/src/core_commands/overlay/use_.rs b/crates/nu-command/src/core_commands/overlay/use_.rs index 20eee56795..61df0f9fc2 100644 --- a/crates/nu-command/src/core_commands/overlay/use_.rs +++ b/crates/nu-command/src/core_commands/overlay/use_.rs @@ -130,6 +130,9 @@ impl Command for OverlayUse { if let Some(block_id) = module.env_block { let maybe_path = find_in_dirs_env(&name_arg.item, engine_state, caller_stack)?; + let block = engine_state.get_block(block_id); + let mut callee_stack = caller_stack.gather_captures(&block.captures); + if let Some(path) = &maybe_path { // Set the currently evaluated directory, if the argument is a valid path let mut parent = path.clone(); @@ -137,12 +140,9 @@ impl Command for OverlayUse { let file_pwd = Value::string(parent.to_string_lossy(), call.head); - caller_stack.add_env_var("FILE_PWD".to_string(), file_pwd); + callee_stack.add_env_var("FILE_PWD".to_string(), file_pwd); } - let block = engine_state.get_block(block_id); - let mut callee_stack = caller_stack.gather_captures(&block.captures); - let _ = eval_block( engine_state, &mut callee_stack, @@ -157,11 +157,6 @@ impl Command for OverlayUse { // Merge the block's environment to the current stack redirect_env(engine_state, caller_stack, &callee_stack); - - if maybe_path.is_some() { - // Remove the file-relative PWD, if the argument is a valid path - caller_stack.remove_env_var(engine_state, "FILE_PWD"); - } } else { caller_stack.add_overlay(overlay_name); }