Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Suggest cargo-search on bad commands #12840

Merged
merged 1 commit into from
Oct 18, 2023
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
7 changes: 3 additions & 4 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c);

anyhow::format_err!(
"no such command: `{}`{}\n\n\t\
View all installed commands with `cargo --list`",
cmd,
did_you_mean
"no such command: `{cmd}`{did_you_mean}\n\n\t\
View all installed commands with `cargo --list`\n\t\
Find a package to install `{cmd}` with `cargo search cargo-{cmd}`",
)
};

Expand Down
12 changes: 9 additions & 3 deletions tests/testsuite/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ fn find_closest_dont_correct_nonsense() {
"\
[ERROR] no such command: `there-is-no-way-that-there-is-a-command-close-to-this`

<tab>View all installed commands with `cargo --list`",
<tab>View all installed commands with `cargo --list`
<tab>Find a package to install `there-is-no-way-that-there-is-a-command-close-to-this` with `cargo search cargo-there-is-no-way-that-there-is-a-command-close-to-this`
",
)
.run();
}
Expand All @@ -307,7 +309,9 @@ fn displays_subcommand_on_error() {
"\
[ERROR] no such command: `invalid-command`

<tab>View all installed commands with `cargo --list`",
<tab>View all installed commands with `cargo --list`
<tab>Find a package to install `invalid-command` with `cargo search cargo-invalid-command`
",
)
.run();
}
Expand Down Expand Up @@ -529,7 +533,9 @@ error: no such command: `bluid`

<tab>Did you mean `build`?

<tab>View all installed commands with `cargo --list`",
<tab>View all installed commands with `cargo --list`
<tab>Find a package to install `bluid` with `cargo search cargo-bluid`
",
)
.run();
}
1 change: 1 addition & 0 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ error: no such command: `echo`
<tab>Did you mean `bench`?

<tab>View all installed commands with `cargo --list`
<tab>Find a package to install `echo` with `cargo search cargo-echo`
",
)
.run();
Expand Down