Skip to content

Commit

Permalink
Better suggestion for unsupported silent flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Sep 28, 2023
1 parent 61648f5 commit 5d8009a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn cli() -> Command {
.arg(unsupported("relative-path"))
.arg(unsupported("only-git-deps"))
.arg(unsupported("disallow-duplicates"))
.arg_quiet()
.arg_quiet_without_unknown_silent_arg_tip()
.arg_manifest_path()
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help vendor</>` for more detailed information.\n"
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ pub trait CommandExt: Sized {
}

fn arg_quiet(self) -> Self {
let unsupported_silent_arg = {
let value_parser = UnknownArgumentValueParser::suggest_arg("--quiet");
flag("silent", "")
.short('s')
.value_parser(value_parser)
.hide(true)
};
self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
._arg(unsupported_silent_arg)
}

fn arg_quiet_without_unknown_silent_arg_tip(self) -> Self {
self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ fn unsupported_silent_arg() {
p.cargo("run -s")
.with_stderr(
"\
error: unexpected argument '-s' found
error: unexpected argument '--silent' found
tip: to pass '-s' as a value, use '-- -s'
tip: a similar argument exists: '--quiet'
Usage: cargo run [OPTIONS] [args]...
Expand All @@ -63,7 +63,7 @@ For more information, try '--help'.
"\
error: unexpected argument '--silent' found
tip: to pass '--silent' as a value, use '-- --silent'
tip: a similar argument exists: '--quiet'
Usage: cargo run [OPTIONS] [args]...
Expand Down

0 comments on commit 5d8009a

Please sign in to comment.