Skip to content

Commit

Permalink
fix(cli): Don't use 'did you mean' on unknown command errors
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 3, 2025
1 parent e090b6f commit c2023a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
args.into_iter().map(|os| os.to_string_lossy()).join(" ")
)
};
format!("\n\tDid you mean the command `{suggested_command} {actual_args}{args}`")
format!("\n\thelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
} else {
"".to_owned()
};
let suggested_script = if let Some(suggested_script) = suggested_script(cmd) {
format!("\n\tDid you mean the file `{suggested_script}`")
format!("\n\thelp: there is a script with a similar name: `{suggested_script}`")
} else {
"".to_owned()
};
Expand All @@ -153,12 +153,12 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
args.into_iter().map(|os| os.to_string_lossy()).join(" ")
)
};
format!("\n\tDid you mean the command `{suggested_command} {actual_args}{args}`")
format!("\n\thelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
} else {
"".to_owned()
};
let suggested_script = if let Some(suggested_script) = suggested_script(cmd) {
format!("\n\tDid you mean the file `{suggested_script}` with `-Zscript`")
format!("\n\thelp: there is a script with a similar name: `{suggested_script}` (requires `-Zscript`)")
} else {
"".to_owned()
};
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn did_you_mean_file() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] no such file or subcommand `foo.rs`
Did you mean the file `./food.rs`
[HELP] there is a script with a similar name: `./food.rs`
"#]])
.run();
Expand All @@ -648,7 +648,7 @@ fn did_you_mean_file_stable() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] no such subcommand `foo.rs`
Did you mean the file `./food.rs` with `-Zscript`
[HELP] there is a script with a similar name: `./food.rs` (requires `-Zscript`)
"#]])
.run();
Expand All @@ -664,7 +664,7 @@ fn did_you_mean_command() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] no such file or subcommand `build--manifest-path=./Cargo.toml`
Did you mean the command `build --manifest-path=./Cargo.toml`
[HELP] there is a command with a similar name: `build --manifest-path=./Cargo.toml`
"#]])
.run();
Expand All @@ -680,7 +680,7 @@ fn did_you_mean_command_stable() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] no such subcommand `build--manifest-path=./Cargo.toml`
Did you mean the command `build --manifest-path=./Cargo.toml`
[HELP] there is a command with a similar name: `build --manifest-path=./Cargo.toml`
"#]])
.run();
Expand Down

0 comments on commit c2023a1

Please sign in to comment.