Skip to content

Commit cacebf8

Browse files
committed
Auto merge of #12777 - hi-rustin:rustin-patch-short-config-flag, r=weihanglo
Add test for unsupported short config flag
2 parents 5a2ea19 + 2400e42 commit cacebf8

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/bin/cargo/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
618618
.help_heading(heading::MANIFEST_OPTIONS)
619619
.global(true),
620620
)
621-
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
621+
.arg_config()
622622
.arg(
623623
Arg::new("unstable-features")
624624
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")

src/cargo/util/command_prelude.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,21 @@ pub trait CommandExt: Sized {
378378
)
379379
._arg(unsupported_short_arg)
380380
}
381+
382+
fn arg_config(self) -> Self {
383+
let unsupported_short_arg = {
384+
let value_parser = UnknownArgumentValueParser::suggest_arg("--config");
385+
Arg::new("unsupported-short-config-flag")
386+
.help("")
387+
.short('c')
388+
.value_parser(value_parser)
389+
.action(ArgAction::SetTrue)
390+
.global(true)
391+
.hide(true)
392+
};
393+
self._arg(unsupported_short_arg)
394+
._arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
395+
}
381396
}
382397

383398
impl CommandExt for Command {

tests/testsuite/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ For more information, try '--help'.
158158
.run();
159159
}
160160

161+
#[cargo_test]
162+
fn cargo_compile_with_unsupported_short_config_flag() {
163+
let p = project()
164+
.file("Cargo.toml", &basic_bin_manifest("foo"))
165+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
166+
.build();
167+
168+
p.cargo("build -c net.git-fetch-with-cli=true")
169+
.with_stderr(
170+
"\
171+
error: unexpected argument '-c' found
172+
173+
tip: a similar argument exists: '--config'
174+
175+
Usage: cargo[EXE] build [OPTIONS]
176+
177+
For more information, try '--help'.
178+
",
179+
)
180+
.with_status(1)
181+
.run();
182+
}
183+
161184
#[cargo_test]
162185
fn cargo_compile_with_workspace_excluded() {
163186
let p = project().file("src/main.rs", "fn main() {}").build();

0 commit comments

Comments
 (0)