mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
run_external: only suggest alternative commands when file not found (#6311)
This commit is contained in:
@ -205,6 +205,9 @@ impl ExternalCommand {
|
||||
|
||||
match child {
|
||||
Err(err) => {
|
||||
match err.kind() {
|
||||
// If file not found, try suggesting alternative commands to the user
|
||||
std::io::ErrorKind::NotFound => {
|
||||
// recommend a replacement if the user tried a deprecated command
|
||||
let command_name_lower = self.name.item.to_lowercase();
|
||||
let deprecated = crate::deprecated_commands();
|
||||
@ -220,8 +223,6 @@ impl ExternalCommand {
|
||||
));
|
||||
}
|
||||
|
||||
// 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}'?"),
|
||||
@ -234,6 +235,14 @@ impl ExternalCommand {
|
||||
self.name.span,
|
||||
))
|
||||
}
|
||||
// otherwise, a default error message
|
||||
_ => Err(ShellError::ExternalCommand(
|
||||
"can't run executable".into(),
|
||||
err.to_string(),
|
||||
self.name.span,
|
||||
)),
|
||||
}
|
||||
}
|
||||
Ok(mut child) => {
|
||||
if !input.is_nothing() {
|
||||
let mut engine_state = engine_state.clone();
|
||||
|
Reference in New Issue
Block a user