mirror of
https://github.com/nushell/nushell.git
synced 2025-06-13 05:26:59 +02:00
overlay new: add --reload(-r)
flag (#15849)
# Description Close: #15747 To support `reload` feature, we just need to save `caller_stack` before adding overlay, then redirect_env back after the overlay is added. # User-Facing Changes NaN # Tests + Formatting Added 1 test # After Submitting NaN
This commit is contained in:
parent
eb9eb09ac5
commit
222c307648
@ -1,4 +1,4 @@
|
|||||||
use nu_engine::command_prelude::*;
|
use nu_engine::{command_prelude::*, redirect_env};
|
||||||
use nu_protocol::engine::CommandType;
|
use nu_protocol::engine::CommandType;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -18,6 +18,11 @@ impl Command for OverlayNew {
|
|||||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||||
.allow_variants_without_examples(true)
|
.allow_variants_without_examples(true)
|
||||||
.required("name", SyntaxShape::String, "Name of the overlay.")
|
.required("name", SyntaxShape::String, "Name of the overlay.")
|
||||||
|
.switch(
|
||||||
|
"reload",
|
||||||
|
"If the overlay already exists, reload its environment.",
|
||||||
|
Some('r'),
|
||||||
|
)
|
||||||
// TODO:
|
// TODO:
|
||||||
// .switch(
|
// .switch(
|
||||||
// "prefix",
|
// "prefix",
|
||||||
@ -41,13 +46,20 @@ This command is a parser keyword. For details, check:
|
|||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
caller_stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
_input: PipelineData,
|
_input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let name_arg: Spanned<String> = call.req(engine_state, stack, 0)?;
|
let name_arg: Spanned<String> = call.req(engine_state, caller_stack, 0)?;
|
||||||
|
let reload = call.has_flag(engine_state, caller_stack, "reload")?;
|
||||||
|
|
||||||
stack.add_overlay(name_arg.item);
|
if reload {
|
||||||
|
let callee_stack = caller_stack.clone();
|
||||||
|
caller_stack.add_overlay(name_arg.item);
|
||||||
|
redirect_env(engine_state, caller_stack, &callee_stack);
|
||||||
|
} else {
|
||||||
|
caller_stack.add_overlay(name_arg.item);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(PipelineData::empty())
|
Ok(PipelineData::empty())
|
||||||
}
|
}
|
||||||
|
@ -1377,6 +1377,23 @@ fn alias_overlay_new() {
|
|||||||
assert_eq!(actual_repl.out, "eggs");
|
assert_eq!(actual_repl.out, "eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overlay_new_with_reload() {
|
||||||
|
let inp = &[
|
||||||
|
"overlay new spam",
|
||||||
|
"$env.foo = 'bar'",
|
||||||
|
"overlay hide spam",
|
||||||
|
"overlay new spam -r",
|
||||||
|
"'foo' in $env",
|
||||||
|
];
|
||||||
|
|
||||||
|
let actual = nu!(&inp.join("; "));
|
||||||
|
let actual_repl = nu!(nu_repl_code(inp));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "false");
|
||||||
|
assert_eq!(actual_repl.out, "false");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn overlay_use_module_dir() {
|
fn overlay_use_module_dir() {
|
||||||
let import = "overlay use samples/spam";
|
let import = "overlay use samples/spam";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user