mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Allow both dashes and underscores for Z flags
This makes it a little easier to match whatever the natural formatting is for where you're setting unstable options -- CLI or config file.
This commit is contained in:
parent
4aede8c784
commit
9cb1ef88b6
@ -429,7 +429,9 @@ impl CliUnstable {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
};
|
};
|
||||||
|
|
||||||
match k {
|
// Permit dashes or underscores in parsing these
|
||||||
|
let normalized_key = k.replace("_", "-");
|
||||||
|
match normalized_key.as_str() {
|
||||||
"print-im-a-teapot" => self.print_im_a_teapot = parse_bool(k, v)?,
|
"print-im-a-teapot" => self.print_im_a_teapot = parse_bool(k, v)?,
|
||||||
"unstable-options" => self.unstable_options = parse_empty(k, v)?,
|
"unstable-options" => self.unstable_options = parse_empty(k, v)?,
|
||||||
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
|
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
Experimental Cargo features are only available on the nightly channel. You
|
Experimental Cargo features are only available on the nightly channel. You
|
||||||
typically use one of the `-Z` flags to enable them. Run `cargo -Z help` to
|
typically use one of the `-Z` flags to enable them. Run `cargo -Z help` to
|
||||||
see a list of flags available.
|
see a list of flags available. All Z flags accept either dashes or underscores
|
||||||
|
as separators.
|
||||||
|
|
||||||
`-Z unstable-options` is a generic flag for enabling other unstable
|
`-Z unstable-options` is a generic flag for enabling other unstable
|
||||||
command-line flags. Options requiring this will be called out below.
|
command-line flags. Options requiring this will be called out below.
|
||||||
|
@ -267,6 +267,26 @@ fn rerooted_remains() {
|
|||||||
assert_eq!(config.get::<String>("c").unwrap(), "cli2");
|
assert_eq!(config.get::<String>("c").unwrap(), "cli2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn unstable_dash_underscore_interchangable() {
|
||||||
|
// Confirm unstable flag parsing treats underscores and dashes
|
||||||
|
// interchangably when coming from the CLI.
|
||||||
|
let config = ConfigBuilder::new()
|
||||||
|
.unstable_flag("print_im_a_teapot")
|
||||||
|
.build();
|
||||||
|
assert_eq!(config.cli_unstable().print_im_a_teapot, true);
|
||||||
|
|
||||||
|
let config = ConfigBuilder::new()
|
||||||
|
.unstable_flag("print-im-a-teapot")
|
||||||
|
.build();
|
||||||
|
assert_eq!(config.cli_unstable().print_im_a_teapot, true);
|
||||||
|
|
||||||
|
let config = ConfigBuilder::new()
|
||||||
|
.unstable_flag("print_im-a_teapot")
|
||||||
|
.build();
|
||||||
|
assert_eq!(config.cli_unstable().print_im_a_teapot, true);
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn bad_parse() {
|
fn bad_parse() {
|
||||||
// Fail to TOML parse.
|
// Fail to TOML parse.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user