mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #12788 - hi-rustin:rustin-patch-short-Z, r=epage
Add unsupported lowercase `-z` flag suggestion for `-Z` flag
This commit is contained in:
commit
c97c906b79
@ -2,7 +2,7 @@ use anyhow::{anyhow, Context as _};
|
|||||||
use cargo::core::shell::Shell;
|
use cargo::core::shell::Shell;
|
||||||
use cargo::core::{features, CliUnstable};
|
use cargo::core::{features, CliUnstable};
|
||||||
use cargo::{self, drop_print, drop_println, CargoResult, CliResult, Config};
|
use cargo::{self, drop_print, drop_println, CargoResult, CliResult, Config};
|
||||||
use clap::{Arg, ArgMatches};
|
use clap::{builder::UnknownArgumentValueParser, Arg, ArgMatches};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@ -618,15 +618,29 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
|
|||||||
.help_heading(heading::MANIFEST_OPTIONS)
|
.help_heading(heading::MANIFEST_OPTIONS)
|
||||||
.global(true),
|
.global(true),
|
||||||
)
|
)
|
||||||
.arg_config()
|
// Better suggestion for the unsupported short config flag.
|
||||||
.arg(
|
.arg( Arg::new("unsupported-short-config-flag")
|
||||||
Arg::new("unstable-features")
|
.help("")
|
||||||
|
.short('c')
|
||||||
|
.value_parser(UnknownArgumentValueParser::suggest_arg("--config"))
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
|
.global(true)
|
||||||
|
.hide(true))
|
||||||
|
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
|
||||||
|
// Better suggestion for the unsupported lowercase unstable feature flag.
|
||||||
|
.arg( Arg::new("unsupported-lowercase-unstable-feature-flag")
|
||||||
|
.help("")
|
||||||
|
.short('z')
|
||||||
|
.value_parser(UnknownArgumentValueParser::suggest_arg("-Z"))
|
||||||
|
.action(ArgAction::SetTrue)
|
||||||
|
.global(true)
|
||||||
|
.hide(true))
|
||||||
|
.arg(Arg::new("unstable-features")
|
||||||
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
|
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
|
||||||
.short('Z')
|
.short('Z')
|
||||||
.value_name("FLAG")
|
.value_name("FLAG")
|
||||||
.action(ArgAction::Append)
|
.action(ArgAction::Append)
|
||||||
.global(true),
|
.global(true))
|
||||||
)
|
|
||||||
.subcommands(commands::builtin())
|
.subcommands(commands::builtin())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,21 +378,6 @@ pub trait CommandExt: Sized {
|
|||||||
)
|
)
|
||||||
._arg(unsupported_short_arg)
|
._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 {
|
impl CommandExt for Command {
|
||||||
|
@ -244,6 +244,33 @@ fn cargo_compile_directory_not_cwd() {
|
|||||||
assert!(p.bin("foo").is_file());
|
assert!(p.bin("foo").is_file());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn cargo_compile_with_unsupported_short_unstable_feature_flag() {
|
||||||
|
let p = project()
|
||||||
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
||||||
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
||||||
|
.file(".cargo/config.toml", &"")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("-zunstable-options -C foo build")
|
||||||
|
.masquerade_as_nightly_cargo(&["chdir"])
|
||||||
|
.cwd(p.root().parent().unwrap())
|
||||||
|
.with_stderr(
|
||||||
|
"\
|
||||||
|
error: unexpected argument '-z' found
|
||||||
|
|
||||||
|
tip: a similar argument exists: '-Z'
|
||||||
|
|
||||||
|
Usage: cargo [+toolchain] [OPTIONS] [COMMAND]
|
||||||
|
cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]...
|
||||||
|
|
||||||
|
For more information, try '--help'.
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.with_status(1)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn cargo_compile_directory_not_cwd_with_invalid_config() {
|
fn cargo_compile_directory_not_cwd_with_invalid_config() {
|
||||||
let p = project()
|
let p = project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user