mirror of
https://github.com/nushell/nushell.git
synced 2024-11-08 09:34:30 +01:00
Improve erroring of config nu
and config env
(#6730)
* improve errors for `config nu` and `config env` * fix tests
This commit is contained in:
parent
e22f2e9f13
commit
9d77e3fc7c
@ -37,7 +37,7 @@ impl Command for ConfigEnv {
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let env_vars_str = env_to_strings(engine_state, stack)?;
|
||||
@ -59,7 +59,7 @@ impl Command for ConfigEnv {
|
||||
|
||||
let name = Spanned {
|
||||
item: get_editor(engine_state, stack)?,
|
||||
span: Span { start: 0, end: 0 },
|
||||
span: call.head,
|
||||
};
|
||||
|
||||
let args = vec![Spanned {
|
||||
@ -76,6 +76,6 @@ impl Command for ConfigEnv {
|
||||
env_vars: env_vars_str,
|
||||
};
|
||||
|
||||
command.run_with_input(engine_state, stack, input)
|
||||
command.run_with_input(engine_state, stack, input, true)
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ impl Command for ConfigNu {
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let env_vars_str = env_to_strings(engine_state, stack)?;
|
||||
@ -59,7 +59,7 @@ impl Command for ConfigNu {
|
||||
|
||||
let name = Spanned {
|
||||
item: get_editor(engine_state, stack)?,
|
||||
span: Span { start: 0, end: 0 },
|
||||
span: call.head,
|
||||
};
|
||||
|
||||
let args = vec![Spanned {
|
||||
@ -76,6 +76,6 @@ impl Command for ConfigNu {
|
||||
env_vars: env_vars_str,
|
||||
};
|
||||
|
||||
command.run_with_input(engine_state, stack, input)
|
||||
command.run_with_input(engine_state, stack, input, true)
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl Command for External {
|
||||
redirect_stderr,
|
||||
env_vars: env_vars_str,
|
||||
};
|
||||
command.run_with_input(engine_state, stack, input)
|
||||
command.run_with_input(engine_state, stack, input, false)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
@ -144,6 +144,7 @@ impl ExternalCommand {
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
input: PipelineData,
|
||||
reconfirm_command_name: bool,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let head = self.name.span;
|
||||
|
||||
@ -262,8 +263,23 @@ impl ExternalCommand {
|
||||
|
||||
let suggestion = suggest_command(&self.name.item, engine_state);
|
||||
let label = match suggestion {
|
||||
Some(s) => format!("did you mean '{s}'?"),
|
||||
None => "can't run executable".into(),
|
||||
Some(s) => {
|
||||
if reconfirm_command_name {
|
||||
format!(
|
||||
"'{}' was not found, did you mean '{s}'?",
|
||||
self.name.item
|
||||
)
|
||||
} else {
|
||||
format!("did you mean '{s}'?")
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if reconfirm_command_name {
|
||||
format!("executable '{}' was not found", self.name.item)
|
||||
} else {
|
||||
"executable was not found".into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Err(ShellError::ExternalCommand(
|
||||
|
@ -284,12 +284,12 @@ fn source_env_is_scoped() {
|
||||
|
||||
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
|
||||
|
||||
assert!(actual.err.contains("can't run executable"));
|
||||
assert!(actual.err.contains("executable was not found"));
|
||||
|
||||
let inp = &[r#"source-env spam.nu"#, r#"nor-similar-to-this"#];
|
||||
|
||||
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
|
||||
|
||||
assert!(actual.err.contains("can't run executable"));
|
||||
assert!(actual.err.contains("executable was not found"));
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user