Skip to content

Commit e3acdd3

Browse files
committed
Auto merge of #12723 - hi-rustin:rustin-patch-silent, r=weihanglo
Add better suggestion for the unsupported silent flag
2 parents 01846d9 + 44d955b commit e3acdd3

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/bin/cargo/commands/vendor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn cli() -> Command {
3636
.arg(unsupported("relative-path"))
3737
.arg(unsupported("only-git-deps"))
3838
.arg(unsupported("disallow-duplicates"))
39-
.arg_quiet()
39+
.arg_quiet_without_unknown_silent_arg_tip()
4040
.arg_manifest_path()
4141
.after_help(color_print::cstr!(
4242
"Run `<cyan,bold>cargo help vendor</>` for more detailed information.\n"

src/cargo/util/command_prelude.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ pub trait CommandExt: Sized {
331331
}
332332

333333
fn arg_quiet(self) -> Self {
334+
let unsupported_silent_arg = {
335+
let value_parser = UnknownArgumentValueParser::suggest_arg("--quiet");
336+
flag("silent", "")
337+
.short('s')
338+
.value_parser(value_parser)
339+
.hide(true)
340+
};
341+
self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
342+
._arg(unsupported_silent_arg)
343+
}
344+
345+
fn arg_quiet_without_unknown_silent_arg_tip(self) -> Self {
334346
self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
335347
}
336348

tests/testsuite/run.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ fn quiet_arg() {
3737
.run();
3838
}
3939

40+
#[cargo_test]
41+
fn unsupported_silent_arg() {
42+
let p = project()
43+
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
44+
.build();
45+
46+
p.cargo("run -s")
47+
.with_stderr(
48+
"\
49+
error: unexpected argument '--silent' found
50+
51+
tip: a similar argument exists: '--quiet'
52+
53+
Usage: cargo[EXE] run [OPTIONS] [args]...
54+
55+
For more information, try '--help'.
56+
",
57+
)
58+
.with_status(1)
59+
.run();
60+
61+
p.cargo("run --silent")
62+
.with_stderr(
63+
"\
64+
error: unexpected argument '--silent' found
65+
66+
tip: a similar argument exists: '--quiet'
67+
68+
Usage: cargo[EXE] run [OPTIONS] [args]...
69+
70+
For more information, try '--help'.
71+
",
72+
)
73+
.with_status(1)
74+
.run();
75+
}
76+
4077
#[cargo_test]
4178
fn quiet_arg_and_verbose_arg() {
4279
let p = project()

0 commit comments

Comments
 (0)