Revert misfeatures

Per comments on the PR, a couple changes need to be backed out.
This commit is contained in:
Alexander Berghage 2020-06-29 19:47:21 -06:00 committed by Alex Berghage
parent 6d7421cacb
commit 48a6f59ec3
2 changed files with 6 additions and 47 deletions

View file

@ -46,7 +46,6 @@
//! we'll be sure to update this documentation!
use std::cell::Cell;
use std::collections::HashMap;
use std::env;
use std::fmt;
use std::str::FromStr;
@ -361,7 +360,6 @@ pub struct CliUnstable {
}
impl CliUnstable {
/// Update unstable options in-place from a slice of flag strings
pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> {
if !flags.is_empty() && !nightly_features_allowed() {
bail!(
@ -373,33 +371,16 @@ impl CliUnstable {
);
}
for flag in flags {
let mut parts = flag.splitn(2, '=');
let k = parts.next().unwrap();
let v = parts.next();
self.add(k, v)?;
self.add(flag)?;
}
Ok(())
}
/// Read unstable options from a hashmap, updating in-place.
/// Intended for consuming unstable settings from config files
pub fn update_with_table(&mut self, flags: &HashMap<String, String>) -> CargoResult<()> {
if !flags.is_empty() && !nightly_features_allowed() {
bail!(
"the `-Z` flag is only accepted on the nightly channel of Cargo, \
but this is the `{}` channel\n\
{}",
channel(),
SEE_CHANNELS
);
}
for (k, v) in flags {
self.add(&k, Some(v.as_str()))?;
}
Ok(())
}
fn add(&mut self, flag: &str) -> CargoResult<()> {
let mut parts = flag.splitn(2, '=');
let k = parts.next().unwrap();
let v = parts.next();
fn add(&mut self, k: &str, v: Option<&str>) -> CargoResult<()> {
fn parse_bool(key: &str, value: Option<&str>) -> CargoResult<bool> {
match value {
None | Some("yes") => Ok(true),
@ -430,9 +411,7 @@ impl CliUnstable {
Ok(true)
};
// Permit dashes or underscores in parsing these
let normalized_key = k.replace("_", "-");
match normalized_key.as_str() {
match k {
"print-im-a-teapot" => self.print_im_a_teapot = parse_bool(k, v)?,
"unstable-options" => self.unstable_options = parse_empty(k, v)?,
"no-index-update" => self.no_index_update = parse_empty(k, v)?,

View file

@ -267,26 +267,6 @@ fn rerooted_remains() {
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]
fn bad_parse() {
// Fail to TOML parse.