mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:25:03 +02:00
Try to make hide-env respects overlays (#15904)
# Description Closes: #15755 I think it's a good feature, to achieve this, we need to get all hidden envs(it's defined in `get_hidden_env_vars`, and then restore these envs back to stack) # User-Facing Changes ### Before ```nushell > $env.foo = 'bar' > overlay new xxx > hide-env foo > overlay hide xxx > $env.foo Error: nu:🐚:column_not_found × Cannot find column 'foo' ╭─[entry #21:5:1] 4 │ overlay hide xxx 5 │ $env.foo · ────┬───┬ · │ ╰── value originates here · ╰── cannot find column 'foo' ╰──── ``` ### After ```nushell > $env.foo = 'bar' > overlay new xxx > hide-env foo > overlay hide xxx > $env.foo bar ``` ## Note But it doesn't work if it runs the example code in script: `nu -c "$env.foo = 'bar'; overlay new xxx; hide-env foo; overlay hide xxx; $env.foo"` still raises an error says `foo` doesn't found. That's because if we run the script at once, the envs in stack doesn't have a chance to merge back into `engine_state`, which is only called in `repl`. It introduces some sort of inconsistency, but I think users use overlays mostly in repl, so it's good to have such feature first. # Tests + Formatting Added 2 tests # After Submitting NaN
This commit is contained in:
@ -86,12 +86,16 @@ impl Command for OverlayHide {
|
||||
vec![]
|
||||
};
|
||||
|
||||
// also restore env vars which has been hidden
|
||||
let env_vars_to_restore = stack.get_hidden_env_vars(&overlay_name.item, engine_state);
|
||||
stack.remove_overlay(&overlay_name.item);
|
||||
for (name, val) in env_vars_to_restore {
|
||||
stack.add_env_var(name, val);
|
||||
}
|
||||
|
||||
for (name, val) in env_vars_to_keep {
|
||||
stack.add_env_var(name, val);
|
||||
}
|
||||
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user