Skip to content

Commit f9719dc

Browse files
committed
add unsupported lowercase flag suggestion for -Z flag
Signed-off-by: hi-rustin <[email protected]>
1 parent 0108d5b commit f9719dc

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/bin/cargo/cli.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,7 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
619619
.global(true),
620620
)
621621
.arg_config()
622-
.arg(
623-
Arg::new("unstable-features")
624-
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
625-
.short('Z')
626-
.value_name("FLAG")
627-
.action(ArgAction::Append)
628-
.global(true),
629-
)
622+
.arg_unstable_feature()
630623
.subcommands(commands::builtin())
631624
}
632625

src/cargo/util/command_prelude.rs

+22
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,28 @@ pub trait CommandExt: Sized {
393393
self._arg(unsupported_short_arg)
394394
._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
395395
}
396+
397+
fn arg_unstable_feature(self) -> Self {
398+
let unsupported_short_arg = {
399+
let value_parser = UnknownArgumentValueParser::suggest_arg("-Z");
400+
Arg::new("unsupported-lowercase-unstable-feature-flag")
401+
.help("")
402+
.short('z')
403+
.value_parser(value_parser)
404+
.action(ArgAction::SetTrue)
405+
.global(true)
406+
.hide(true)
407+
};
408+
self._arg(
409+
Arg::new("unstable-features")
410+
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
411+
.short('Z')
412+
.value_name("FLAG")
413+
.action(ArgAction::Append)
414+
.global(true),
415+
)
416+
._arg(unsupported_short_arg)
417+
}
396418
}
397419

398420
impl CommandExt for Command {

tests/testsuite/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ fn cargo_compile_with_unsupported_short_unstable_feature_flag() {
259259
"\
260260
error: unexpected argument '-z' found
261261
262+
tip: a similar argument exists: '-Z'
263+
262264
Usage: cargo [+toolchain] [OPTIONS] [COMMAND]
263265
cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]...
264266

0 commit comments

Comments
 (0)