forked from extern/nushell
run_external: only suggest alternative commands when file not found (#6311)
This commit is contained in:
parent
cb18dd5200
commit
3b6c4c1bb5
@ -205,34 +205,43 @@ impl ExternalCommand {
|
|||||||
|
|
||||||
match child {
|
match child {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// recommend a replacement if the user tried a deprecated command
|
match err.kind() {
|
||||||
let command_name_lower = self.name.item.to_lowercase();
|
// If file not found, try suggesting alternative commands to the user
|
||||||
let deprecated = crate::deprecated_commands();
|
std::io::ErrorKind::NotFound => {
|
||||||
if deprecated.contains_key(&command_name_lower) {
|
// recommend a replacement if the user tried a deprecated command
|
||||||
let replacement = match deprecated.get(&command_name_lower) {
|
let command_name_lower = self.name.item.to_lowercase();
|
||||||
Some(s) => s.clone(),
|
let deprecated = crate::deprecated_commands();
|
||||||
None => "".to_string(),
|
if deprecated.contains_key(&command_name_lower) {
|
||||||
};
|
let replacement = match deprecated.get(&command_name_lower) {
|
||||||
return Err(ShellError::DeprecatedCommand(
|
Some(s) => s.clone(),
|
||||||
command_name_lower,
|
None => "".to_string(),
|
||||||
replacement,
|
};
|
||||||
|
return Err(ShellError::DeprecatedCommand(
|
||||||
|
command_name_lower,
|
||||||
|
replacement,
|
||||||
|
self.name.span,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Err(ShellError::ExternalCommand(
|
||||||
|
label,
|
||||||
|
err.to_string(),
|
||||||
|
self.name.span,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
// otherwise, a default error message
|
||||||
|
_ => Err(ShellError::ExternalCommand(
|
||||||
|
"can't run executable".into(),
|
||||||
|
err.to_string(),
|
||||||
self.name.span,
|
self.name.span,
|
||||||
));
|
)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we try to run an external but can't, there's a good chance
|
|
||||||
// that the user entered the wrong command name
|
|
||||||
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(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Err(ShellError::ExternalCommand(
|
|
||||||
label,
|
|
||||||
err.to_string(),
|
|
||||||
self.name.span,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
if !input.is_nothing() {
|
if !input.is_nothing() {
|
||||||
|
Loading…
Reference in New Issue
Block a user