Skip to content

Commit 4d5a8aa

Browse files
committed
fix: Align new help messages with their error
1 parent 247540c commit 4d5a8aa

File tree

14 files changed

+71
-71
lines changed

14 files changed

+71
-71
lines changed

src/bin/cargo/commands/run.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
103103
(false, true) => {
104104
let possible_commands = crate::list_commands(gctx);
105105
let is_dir = if manifest_path.is_dir() {
106-
format!("\n\t`{cmd}` is a directory")
106+
format!(": `{cmd}` is a directory")
107107
} else {
108108
"".to_owned()
109109
};
@@ -121,12 +121,12 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
121121
args.into_iter().map(|os| os.to_string_lossy()).join(" ")
122122
)
123123
};
124-
format!("\n\thelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
124+
format!("\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
125125
} else {
126126
"".to_owned()
127127
};
128128
let suggested_script = if let Some(suggested_script) = suggested_script(cmd) {
129-
format!("\n\thelp: there is a script with a similar name: `{suggested_script}`")
129+
format!("\nhelp: there is a script with a similar name: `{suggested_script}`")
130130
} else {
131131
"".to_owned()
132132
};
@@ -153,12 +153,12 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
153153
args.into_iter().map(|os| os.to_string_lossy()).join(" ")
154154
)
155155
};
156-
format!("\n\thelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
156+
format!("\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`")
157157
} else {
158158
"".to_owned()
159159
};
160160
let suggested_script = if let Some(suggested_script) = suggested_script(cmd) {
161-
format!("\n\thelp: there is a script with a similar name: `{suggested_script}` (requires `-Zscript`)")
161+
format!("\nhelp: there is a script with a similar name: `{suggested_script}` (requires `-Zscript`)")
162162
} else {
163163
"".to_owned()
164164
};

src/bin/cargo/main.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,28 @@ fn execute_external_subcommand(gctx: &GlobalContext, cmd: &str, args: &[&OsStr])
278278
let command = match path {
279279
Some(command) => command,
280280
None => {
281-
let script_suggestion = if gctx.cli_unstable().script
282-
&& std::path::Path::new(cmd).is_file()
283-
{
284-
let sep = std::path::MAIN_SEPARATOR;
285-
format!("\n\tTo run the file `{cmd}`, provide a relative path like `.{sep}{cmd}`")
286-
} else {
287-
"".to_owned()
288-
};
281+
let script_suggestion =
282+
if gctx.cli_unstable().script && std::path::Path::new(cmd).is_file() {
283+
let sep = std::path::MAIN_SEPARATOR;
284+
format!(
285+
"\nhelp: To run the file `{cmd}`, provide a relative path like `.{sep}{cmd}`"
286+
)
287+
} else {
288+
"".to_owned()
289+
};
289290
let err = if cmd.starts_with('+') {
290291
anyhow::format_err!(
291-
"no such command: `{cmd}`\n\n\t\
292+
"no such command: `{cmd}`\n\n\
292293
help: invoke `cargo` through `rustup` to handle `+toolchain` directives{script_suggestion}",
293294
)
294295
} else {
295296
let suggestions = list_commands(gctx);
296297
let did_you_mean = closest_msg(cmd, suggestions.keys(), |c| c, "command");
297298

298299
anyhow::format_err!(
299-
"no such command: `{cmd}`{did_you_mean}\n\n\t\
300-
View all installed commands with `cargo --list`\n\t\
301-
Find a package to install `{cmd}` with `cargo search cargo-{cmd}`{script_suggestion}",
300+
"no such command: `{cmd}`{did_you_mean}\n\n\
301+
help: view all installed commands with `cargo --list`\n\
302+
help: find a package to install `{cmd}` with `cargo search cargo-{cmd}`{script_suggestion}",
302303
)
303304
};
304305

src/cargo/util/edit_distance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn closest_msg<'a, T>(
117117
) -> String {
118118
match closest(choice, iter, &key) {
119119
Some(e) => format!(
120-
"\n\n\thelp: a {kind} with a similar name exists: `{}`",
120+
"\n\nhelp: a {kind} with a similar name exists: `{}`",
121121
key(&e)
122122
),
123123
None => String::new(),

tests/testsuite/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ Available bin targets:
13501350
.with_stderr_data(str![[r#"
13511351
[ERROR] no bin target named `a.rs`
13521352
1353-
[HELP] a target with a similar name exists: `a`
1353+
[HELP] a target with a similar name exists: `a`
13541354
13551355
"#]])
13561356
.run();
@@ -1371,7 +1371,7 @@ Available example targets:
13711371
.with_stderr_data(str![[r#"
13721372
[ERROR] no example target named `a.rs`
13731373
1374-
[HELP] a target with a similar name exists: `a`
1374+
[HELP] a target with a similar name exists: `a`
13751375
13761376
"#]])
13771377
.run();
@@ -5908,7 +5908,7 @@ fn target_filters_workspace() {
59085908
.with_stderr_data(str![[r#"
59095909
[ERROR] no example target named `ex`
59105910
5911-
[HELP] a target with a similar name exists: `ex1`
5911+
[HELP] a target with a similar name exists: `ex1`
59125912
59135913
"#]])
59145914
.run();
@@ -5918,7 +5918,7 @@ fn target_filters_workspace() {
59185918
.with_stderr_data(str![[r#"
59195919
[ERROR] no example target matches pattern `ex??`
59205920
5921-
[HELP] a target with a similar name exists: `ex1`
5921+
[HELP] a target with a similar name exists: `ex1`
59225922
59235923
"#]])
59245924
.run();

tests/testsuite/cargo_command.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ fn find_closest_capital_c_to_c() {
186186
.with_stderr_data(str![[r#"
187187
[ERROR] no such command: `C`
188188
189-
[HELP] a command with a similar name exists: `c`
189+
[HELP] a command with a similar name exists: `c`
190190
191-
View all installed commands with `cargo --list`
192-
Find a package to install `C` with `cargo search cargo-C`
191+
[HELP] view all installed commands with `cargo --list`
192+
[HELP] find a package to install `C` with `cargo search cargo-C`
193193
194194
"#]])
195195
.run();
@@ -202,10 +202,10 @@ fn find_closest_capital_b_to_b() {
202202
.with_stderr_data(str![[r#"
203203
[ERROR] no such command: `B`
204204
205-
[HELP] a command with a similar name exists: `b`
205+
[HELP] a command with a similar name exists: `b`
206206
207-
View all installed commands with `cargo --list`
208-
Find a package to install `B` with `cargo search cargo-B`
207+
[HELP] view all installed commands with `cargo --list`
208+
[HELP] find a package to install `B` with `cargo search cargo-B`
209209
210210
"#]])
211211
.run();
@@ -218,10 +218,10 @@ fn find_closest_biuld_to_build() {
218218
.with_stderr_data(str![[r#"
219219
[ERROR] no such command: `biuld`
220220
221-
[HELP] a command with a similar name exists: `build`
221+
[HELP] a command with a similar name exists: `build`
222222
223-
View all installed commands with `cargo --list`
224-
Find a package to install `biuld` with `cargo search cargo-biuld`
223+
[HELP] view all installed commands with `cargo --list`
224+
[HELP] find a package to install `biuld` with `cargo search cargo-biuld`
225225
226226
"#]])
227227
.run();
@@ -276,10 +276,10 @@ fn find_closest_alias() {
276276
.with_stderr_data(str![[r#"
277277
[ERROR] no such command: `myalais`
278278
279-
[HELP] a command with a similar name exists: `myalias`
279+
[HELP] a command with a similar name exists: `myalias`
280280
281-
View all installed commands with `cargo --list`
282-
Find a package to install `myalais` with `cargo search cargo-myalais`
281+
[HELP] view all installed commands with `cargo --list`
282+
[HELP] find a package to install `myalais` with `cargo search cargo-myalais`
283283
284284
"#]])
285285
.run();
@@ -290,8 +290,8 @@ fn find_closest_alias() {
290290
.with_stderr_data(str![[r#"
291291
[ERROR] no such command: `myalais`
292292
293-
View all installed commands with `cargo --list`
294-
Find a package to install `myalais` with `cargo search cargo-myalais`
293+
[HELP] view all installed commands with `cargo --list`
294+
[HELP] find a package to install `myalais` with `cargo search cargo-myalais`
295295
296296
"#]])
297297
.run();
@@ -306,8 +306,8 @@ fn find_closest_dont_correct_nonsense() {
306306
.with_stderr_data(str![[r#"
307307
[ERROR] no such command: `there-is-no-way-that-there-is-a-command-close-to-this`
308308
309-
View all installed commands with `cargo --list`
310-
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`
309+
[HELP] view all installed commands with `cargo --list`
310+
[HELP] 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`
311311
312312
"#]])
313313
.run();
@@ -320,8 +320,8 @@ fn displays_subcommand_on_error() {
320320
.with_stderr_data(str![[r#"
321321
[ERROR] no such command: `invalid-command`
322322
323-
View all installed commands with `cargo --list`
324-
Find a package to install `invalid-command` with `cargo search cargo-invalid-command`
323+
[HELP] view all installed commands with `cargo --list`
324+
[HELP] find a package to install `invalid-command` with `cargo search cargo-invalid-command`
325325
326326
"#]])
327327
.run();
@@ -549,7 +549,7 @@ fn subcommand_leading_plus_output_contains() {
549549
.with_stderr_data(str![[r#"
550550
[ERROR] no such command: `+nightly`
551551
552-
[HELP] invoke `cargo` through `rustup` to handle `+toolchain` directives
552+
[HELP] invoke `cargo` through `rustup` to handle `+toolchain` directives
553553
554554
"#]])
555555
.run();
@@ -562,10 +562,10 @@ fn full_did_you_mean() {
562562
.with_stderr_data(str![[r#"
563563
[ERROR] no such command: `bluid`
564564
565-
[HELP] a command with a similar name exists: `build`
565+
[HELP] a command with a similar name exists: `build`
566566
567-
View all installed commands with `cargo --list`
568-
Find a package to install `bluid` with `cargo search cargo-bluid`
567+
[HELP] view all installed commands with `cargo --list`
568+
[HELP] find a package to install `bluid` with `cargo search cargo-bluid`
569569
570570
"#]])
571571
.run();

tests/testsuite/clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ fn clean_spec_version() {
639639
.with_stderr_data(str![[r#"
640640
[ERROR] package ID specification `baz` did not match any packages
641641
642-
[HELP] a package with a similar name exists: `bar`
642+
[HELP] a package with a similar name exists: `bar`
643643
644644
"#]])
645645
.run();
@@ -694,7 +694,7 @@ fn clean_spec_partial_version() {
694694
.with_stderr_data(str![[r#"
695695
[ERROR] package ID specification `baz` did not match any packages
696696
697-
[HELP] a package with a similar name exists: `bar`
697+
[HELP] a package with a similar name exists: `bar`
698698
699699
"#]])
700700
.run();
@@ -749,7 +749,7 @@ fn clean_spec_partial_version_ambiguous() {
749749
.with_stderr_data(str![[r#"
750750
[ERROR] package ID specification `baz` did not match any packages
751751
752-
[HELP] a package with a similar name exists: `bar`
752+
[HELP] a package with a similar name exists: `bar`
753753
754754
"#]])
755755
.run();

tests/testsuite/help.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ fn help_alias() {
142142
.with_stderr_data(str![[r#"
143143
[ERROR] no such command: `empty-alias`
144144
145-
[HELP] a command with a similar name exists: `empty-alias`
145+
[HELP] a command with a similar name exists: `empty-alias`
146146
147-
View all installed commands with `cargo --list`
148-
Find a package to install `empty-alias` with `cargo search cargo-empty-alias`
147+
[HELP] view all installed commands with `cargo --list`
148+
[HELP] find a package to install `empty-alias` with `cargo search cargo-empty-alias`
149149
150150
"#]])
151151
.run();

tests/testsuite/package_features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ fn non_member_feature() {
737737
.with_stderr_data(str![[r#"
738738
[ERROR] package ID specification `bar` did not match any packages
739739
740-
[HELP] a package with a similar name exists: `foo`
740+
[HELP] a package with a similar name exists: `foo`
741741
742742
"#]])
743743
.run();
@@ -796,7 +796,7 @@ fn non_member_feature() {
796796
.with_stderr_data(str![[r#"
797797
[ERROR] package ID specification `bar` did not match any packages
798798
799-
[HELP] a package with a similar name exists: `foo`
799+
[HELP] a package with a similar name exists: `foo`
800800
801801
"#]])
802802
.run();

tests/testsuite/pkgid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Caused by:
6363
.with_stderr_data(str![[r#"
6464
[ERROR] invalid package ID specification: `./bar`
6565
66-
[HELP] a package with a similar name exists: `bar`
66+
[HELP] a package with a similar name exists: `bar`
6767
6868
Caused by:
6969
package ID specification `./bar` looks like a file path, maybe try [ROOTURL]/foo/bar
@@ -119,7 +119,7 @@ registry+https://github.com/rust-lang/crates.io-index#[email protected]
119119
.with_stderr_data(str![[r#"
120120
[ERROR] package ID specification `crates_io` did not match any packages
121121
122-
[HELP] a package with a similar name exists: `crates-io`
122+
[HELP] a package with a similar name exists: `crates-io`
123123
124124
"#]])
125125
.run();

tests/testsuite/profile_overrides.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn profile_override_warnings() {
7878
[WARNING] profile package spec `[email protected]` in profile `dev` has a version or URL that does not match any of the packages: bar v0.5.0 ([ROOT]/foo/bar)
7979
[WARNING] profile package spec `bart` in profile `dev` did not match any packages
8080
81-
[HELP] a package with a similar name exists: `bar`
81+
[HELP] a package with a similar name exists: `bar`
8282
[WARNING] profile package spec `no-suggestion` in profile `dev` did not match any packages
8383
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
8484
[COMPILING] foo v0.0.1 ([ROOT]/foo)

0 commit comments

Comments
 (0)