Skip to content

Commit

Permalink
Auto merge of #12777 - hi-rustin:rustin-patch-short-config-flag, r=we…
Browse files Browse the repository at this point in the history
…ihanglo

Add test for unsupported short config flag
  • Loading branch information
bors committed Oct 6, 2023
2 parents 5a2ea19 + 2400e42 commit cacebf8
Show file tree
Hide file tree
Showing 3 changed files with 39 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
23 changes: 23 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ For more information, try '--help'.
.run();
}

#[cargo_test]
fn cargo_compile_with_unsupported_short_config_flag() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

p.cargo("build -c net.git-fetch-with-cli=true")
.with_stderr(
"\
error: unexpected argument '-c' found
tip: a similar argument exists: '--config'
Usage: cargo[EXE] build [OPTIONS]
For more information, try '--help'.
",
)
.with_status(1)
.run();
}

#[cargo_test]
fn cargo_compile_with_workspace_excluded() {
let p = project().file("src/main.rs", "fn main() {}").build();
Expand Down

0 comments on commit cacebf8

Please sign in to comment.