Skip to content

Commit

Permalink
add unsupported short suggestion for --config 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 6, 2023
1 parent 9141199 commit 2400e42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
.help_heading(heading::MANIFEST_OPTIONS)
.global(true),
)
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
.arg_config()
.arg(
Arg::new("unstable-features")
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
Expand Down
15 changes: 15 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ pub trait CommandExt: Sized {
)
._arg(unsupported_short_arg)
}

fn arg_config(self) -> Self {
let unsupported_short_arg = {
let value_parser = UnknownArgumentValueParser::suggest_arg("--config");
Arg::new("unsupported-short-config-flag")
.help("")
.short('c')
.value_parser(value_parser)
.action(ArgAction::SetTrue)
.global(true)
.hide(true)
};
self._arg(unsupported_short_arg)
._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
}
}

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 @@ -170,6 +170,8 @@ fn cargo_compile_with_unsupported_short_config_flag() {
"\
error: unexpected argument '-c' found
tip: a similar argument exists: '--config'
Usage: cargo[EXE] build [OPTIONS]
For more information, try '--help'.
Expand Down

0 comments on commit 2400e42

Please sign in to comment.