Skip to content

Commit 709ac17

Browse files
committed
Auto merge of #12840 - epage:suggest, r=hi-rustin
fix(cli): Suggest cargo-search on bad commands This is a low-tech solution alternative to the options proposed in #4682 - Search `[[bin]]`s within all packages in the registry (which aren't tracked atm), suggesting to `cargo install` what is found - Check if `cargo-<cmd>` is in the registry, suggesting `cargo install if it is By suggesting `cargo search`, we are giving them a tool so they can verify if the package is what they want (a `cargo info` would help as a next step). Is is needed? - New users might not know of `cargo search` but they can search on crates.io - New users might not be aware of the `cargo-<cmd>` naming pattern Seems like this can still offer some benefit. Fixes #4682
2 parents 4cf7937 + ec3ed20 commit 709ac17

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/bin/cargo/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,9 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
192192
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c);
193193

194194
anyhow::format_err!(
195-
"no such command: `{}`{}\n\n\t\
196-
View all installed commands with `cargo --list`",
197-
cmd,
198-
did_you_mean
195+
"no such command: `{cmd}`{did_you_mean}\n\n\t\
196+
View all installed commands with `cargo --list`\n\t\
197+
Find a package to install `{cmd}` with `cargo search cargo-{cmd}`",
199198
)
200199
};
201200

tests/testsuite/cargo_command.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ fn find_closest_dont_correct_nonsense() {
294294
"\
295295
[ERROR] no such command: `there-is-no-way-that-there-is-a-command-close-to-this`
296296
297-
<tab>View all installed commands with `cargo --list`",
297+
<tab>View all installed commands with `cargo --list`
298+
<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`
299+
",
298300
)
299301
.run();
300302
}
@@ -307,7 +309,9 @@ fn displays_subcommand_on_error() {
307309
"\
308310
[ERROR] no such command: `invalid-command`
309311
310-
<tab>View all installed commands with `cargo --list`",
312+
<tab>View all installed commands with `cargo --list`
313+
<tab>Find a package to install `invalid-command` with `cargo search cargo-invalid-command`
314+
",
311315
)
312316
.run();
313317
}
@@ -529,7 +533,9 @@ error: no such command: `bluid`
529533
530534
<tab>Did you mean `build`?
531535
532-
<tab>View all installed commands with `cargo --list`",
536+
<tab>View all installed commands with `cargo --list`
537+
<tab>Find a package to install `bluid` with `cargo search cargo-bluid`
538+
",
533539
)
534540
.run();
535541
}

tests/testsuite/script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ error: no such command: `echo`
108108
<tab>Did you mean `bench`?
109109
110110
<tab>View all installed commands with `cargo --list`
111+
<tab>Find a package to install `echo` with `cargo search cargo-echo`
111112
",
112113
)
113114
.run();

0 commit comments

Comments
 (0)