From 083b495223751e646e9721b1698c8596752a4380 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 7 Oct 2023 20:25:21 +0800 Subject: [PATCH] add unsupported lowercase flag suggestion for -Z flag Signed-off-by: hi-rustin --- src/bin/cargo/cli.rs | 9 +-------- src/cargo/util/command_prelude.rs | 22 ++++++++++++++++++++++ tests/testsuite/build.rs | 2 ++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 7c0e3b5ee85f..3189a789c581 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -619,14 +619,7 @@ See 'cargo help <>' for more information on a sp .global(true), ) .arg_config() - .arg( - Arg::new("unstable-features") - .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") - .short('Z') - .value_name("FLAG") - .action(ArgAction::Append) - .global(true), - ) + .arg_unstable_feature() .subcommands(commands::builtin()) } diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index bfc2c45cd057..09857b76f580 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -393,6 +393,28 @@ pub trait CommandExt: Sized { self._arg(unsupported_short_arg) ._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true)) } + + fn arg_unstable_feature(self) -> Self { + let unsupported_short_arg = { + let value_parser = UnknownArgumentValueParser::suggest_arg("-Z"); + Arg::new("unsupported-lowercase-unstable-feature-flag") + .help("") + .short('z') + .value_parser(value_parser) + .action(ArgAction::SetTrue) + .global(true) + .hide(true) + }; + self._arg( + Arg::new("unstable-features") + .help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details") + .short('Z') + .value_name("FLAG") + .action(ArgAction::Append) + .global(true), + ) + ._arg(unsupported_short_arg) + } } impl CommandExt for Command { diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index e64720b1cb12..eccd9b09523e 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -259,6 +259,8 @@ fn cargo_compile_with_unsupported_short_unstable_feature_flag() { "\ error: unexpected argument '-z' found + tip: a similar argument exists: '-Z' + Usage: cargo[EXE] [+toolchain] [OPTIONS] [COMMAND] cargo[EXE] [+toolchain] [OPTIONS] -Zscript [ARGS]...