Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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