Skip to content

Commit

Permalink
add unsupported lowercase flag suggestion for -Z flag
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Oct 7, 2023
1 parent 478506b commit 272c69e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,7 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' 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())
}

Expand Down
22 changes: 22 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]...
Expand Down

0 comments on commit 272c69e

Please sign in to comment.