From 8ae23fdea1c2d5db81bf2cf69e61c5bd525c8cda Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 22 Sep 2023 10:48:10 +0800 Subject: [PATCH] Better suggestion for unsupported silent flag --- src/cargo/util/command_prelude.rs | 8 ++++++++ tests/testsuite/run.rs | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index dcfabb3c2597..20bf1154c169 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -331,7 +331,15 @@ 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_timings(self) -> Self { diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 2d65bb7f7de5..da4a8afe62c6 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]...