Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ fn execute_external_subcommand(gctx: &GlobalContext, cmd: &str, args: &[&OsStr])
)
} else {
let suggestions = list_commands(gctx);
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c, "command");
let did_you_mean = if cmd == "rustfmt" {
"\n\nhelp: a command with a similar name exists: `fmt`".to_string()
} else {
closest_msg(cmd, suggestions.keys(), |c| c, "command")
};

anyhow::format_err!(
"no such command: `{cmd}`{did_you_mean}\n\n\
Expand Down
16 changes: 16 additions & 0 deletions tests/testsuite/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ fn find_closest_capital_b_to_b() {
.run();
}

#[cargo_test]
fn cargo_rustfmt_suggestion() {
cargo_process("rustfmt")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no such command: `rustfmt`

[HELP] a command with a similar name exists: `fmt`

[HELP] view all installed commands with `cargo --list`
[HELP] find a package to install `rustfmt` with `cargo search cargo-rustfmt`

"#]])
.run();
}

#[cargo_test]
fn find_closest_biuld_to_build() {
cargo_process("biuld")
Expand Down