forked from extern/nushell
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,
|
&self,
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
_call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let env_vars_str = env_to_strings(engine_state, stack)?;
|
let env_vars_str = env_to_strings(engine_state, stack)?;
|
||||||
@ -59,7 +59,7 @@ impl Command for ConfigEnv {
|
|||||||
|
|
||||||
let name = Spanned {
|
let name = Spanned {
|
||||||
item: get_editor(engine_state, stack)?,
|
item: get_editor(engine_state, stack)?,
|
||||||
span: Span { start: 0, end: 0 },
|
span: call.head,
|
||||||
};
|
};
|
||||||
|
|
||||||
let args = vec![Spanned {
|
let args = vec![Spanned {
|
||||||
@ -76,6 +76,6 @@ impl Command for ConfigEnv {
|
|||||||
env_vars: env_vars_str,
|
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,
|
&self,
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
_call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let env_vars_str = env_to_strings(engine_state, stack)?;
|
let env_vars_str = env_to_strings(engine_state, stack)?;
|
||||||
@ -59,7 +59,7 @@ impl Command for ConfigNu {
|
|||||||
|
|
||||||
let name = Spanned {
|
let name = Spanned {
|
||||||
item: get_editor(engine_state, stack)?,
|
item: get_editor(engine_state, stack)?,
|
||||||
span: Span { start: 0, end: 0 },
|
span: call.head,
|
||||||
};
|
};
|
||||||
|
|
||||||
let args = vec![Spanned {
|
let args = vec![Spanned {
|
||||||
@ -76,6 +76,6 @@ impl Command for ConfigNu {
|
|||||||
env_vars: env_vars_str,
|
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,
|
redirect_stderr,
|
||||||
env_vars: env_vars_str,
|
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> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
@ -144,6 +144,7 @@ impl ExternalCommand {
|
|||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
stack: &mut Stack,
|
stack: &mut Stack,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
|
reconfirm_command_name: bool,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = self.name.span;
|
let head = self.name.span;
|
||||||
|
|
||||||
@ -262,8 +263,23 @@ impl ExternalCommand {
|
|||||||
|
|
||||||
let suggestion = suggest_command(&self.name.item, engine_state);
|
let suggestion = suggest_command(&self.name.item, engine_state);
|
||||||
let label = match suggestion {
|
let label = match suggestion {
|
||||||
Some(s) => format!("did you mean '{s}'?"),
|
Some(s) => {
|
||||||
None => "can't run executable".into(),
|
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(
|
Err(ShellError::ExternalCommand(
|
||||||
|
@ -284,12 +284,12 @@ fn source_env_is_scoped() {
|
|||||||
|
|
||||||
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
|
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 inp = &[r#"source-env spam.nu"#, r#"nor-similar-to-this"#];
|
||||||
|
|
||||||
let actual = nu!(cwd: dirs.test(), pipeline(&inp.join("; ")));
|
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