From 61648f583e3e16433258f8331b64af04f8308aeb Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 22 Sep 2023 10:46:06 +0800 Subject: [PATCH 1/3] Add test for unsupported silent flag --- tests/testsuite/run.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 64cf4e16c6b..2d65bb7f7de 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -37,6 +37,43 @@ fn quiet_arg() { .run(); } +#[cargo_test] +fn unsupported_silent_arg() { + let p = project() + .file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .build(); + + p.cargo("run -s") + .with_stderr( + "\ +error: unexpected argument '-s' found + + tip: to pass '-s' as a value, use '-- -s' + +Usage: cargo run [OPTIONS] [args]... + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); + + p.cargo("run --silent") + .with_stderr( + "\ +error: unexpected argument '--silent' found + + tip: to pass '--silent' as a value, use '-- --silent' + +Usage: cargo run [OPTIONS] [args]... + +For more information, try '--help'. +", + ) + .with_status(1) + .run(); +} + #[cargo_test] fn quiet_arg_and_verbose_arg() { let p = project() From 5d8009a18952fba0ce881d089c1ec91aba758587 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 22 Sep 2023 10:48:10 +0800 Subject: [PATCH 2/3] Better suggestion for unsupported silent flag --- src/bin/cargo/commands/vendor.rs | 2 +- src/cargo/util/command_prelude.rs | 12 ++++++++++++ tests/testsuite/run.rs | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/bin/cargo/commands/vendor.rs b/src/bin/cargo/commands/vendor.rs index 05e0d7defd5..3f9c2dcaf3e 100644 --- a/src/bin/cargo/commands/vendor.rs +++ b/src/bin/cargo/commands/vendor.rs @@ -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 `cargo help vendor` for more detailed information.\n" diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index dcfabb3c259..bd8889bef2c 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -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')) } diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 2d65bb7f7de..da4a8afe62c 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -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]... @@ -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]... From 44d955b15d1c532f9fd743fcb4a62059c5974e9f Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 28 Sep 2023 10:10:19 +0800 Subject: [PATCH 3/3] Fix test on windows --- tests/testsuite/run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index da4a8afe62c..c58c239acf0 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -50,7 +50,7 @@ error: unexpected argument '--silent' found tip: a similar argument exists: '--quiet' -Usage: cargo run [OPTIONS] [args]... +Usage: cargo[EXE] run [OPTIONS] [args]... For more information, try '--help'. ", @@ -65,7 +65,7 @@ error: unexpected argument '--silent' found tip: a similar argument exists: '--quiet' -Usage: cargo run [OPTIONS] [args]... +Usage: cargo[EXE] run [OPTIONS] [args]... For more information, try '--help'. ",