Auto merge of #12805 - hi-rustin:rustin-patch-target, r=epage

Add unsupported short flag suggestion for `--target` and `--exclude` flags
This commit is contained in:
bors 2023-10-11 02:08:04 +00:00
commit 4ae21bd58f
2 changed files with 81 additions and 0 deletions

View file

@ -64,9 +64,19 @@ pub trait CommandExt: Sized {
all: &'static str,
exclude: &'static str,
) -> Self {
let unsupported_short_arg = {
let value_parser = UnknownArgumentValueParser::suggest_arg("--exclude");
Arg::new("unsupported-short-exclude-flag")
.help("")
.short('x')
.value_parser(value_parser)
.action(ArgAction::SetTrue)
.hide(true)
};
self.arg_package_spec_simple(package)
._arg(flag("workspace", all).help_heading(heading::PACKAGE_SELECTION))
._arg(multi_opt("exclude", "SPEC", exclude).help_heading(heading::PACKAGE_SELECTION))
._arg(unsupported_short_arg)
}
fn arg_package_spec_simple(self, package: &'static str) -> Self {
@ -232,10 +242,20 @@ pub trait CommandExt: Sized {
}
fn arg_target_triple(self, target: &'static str) -> Self {
let unsupported_short_arg = {
let value_parser = UnknownArgumentValueParser::suggest_arg("--target");
Arg::new("unsupported-short-target-flag")
.help("")
.short('t')
.value_parser(value_parser)
.action(ArgAction::SetTrue)
.hide(true)
};
self._arg(
optional_multi_opt("target", "TRIPLE", target)
.help_heading(heading::COMPILATION_OPTIONS),
)
._arg(unsupported_short_arg)
}
fn arg_target_dir(self) -> Self {

View file

@ -4239,6 +4239,30 @@ fn cargo_build_empty_target() {
.run();
}
#[cargo_test]
fn cargo_build_with_unsupported_short_target_flag() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build -t")
.arg("")
.with_stderr(
"\
error: unexpected argument '-t' found
tip: a similar argument exists: '--target'
Usage: cargo[EXE] build [OPTIONS]
For more information, try '--help'.
",
)
.with_status(1)
.run();
}
#[cargo_test]
fn build_all_workspace() {
let p = project()
@ -4304,6 +4328,43 @@ fn build_all_exclude() {
.run();
}
#[cargo_test]
fn cargo_build_with_unsupported_short_exclude_flag() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[workspace]
members = ["bar", "baz"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }")
.build();
p.cargo("build --workspace -x baz")
.with_stderr(
"\
error: unexpected argument '-x' found
tip: a similar argument exists: '--exclude'
Usage: cargo[EXE] build [OPTIONS]
For more information, try '--help'.
",
)
.with_status(1)
.run();
}
#[cargo_test]
fn build_all_exclude_not_found() {
let p = project()