Skip to content

Commit

Permalink
Allow populating CliUnstable from a HashMap
Browse files Browse the repository at this point in the history
This makes it easier to populate unstable
options from configuration files. Might also
help make unstable option tests easier to write.
  • Loading branch information
bearcage committed Jul 8, 2020
1 parent 729e567 commit 1cea4cb
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/cargo/core/features.rs
Expand Up @@ -46,6 +46,7 @@
//! 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;
Expand Down Expand Up @@ -371,16 +372,33 @@ impl CliUnstable {
);
}
for flag in flags {
self.add(flag)?;
let mut parts = flag.splitn(2, '=');
let k = parts.next().unwrap();
let v = parts.next();
self.add(k, v)?;
}
Ok(())
}

fn add(&mut self, flag: &str) -> CargoResult<()> {
let mut parts = flag.splitn(2, '=');
let k = parts.next().unwrap();
let v = parts.next();
/// Read unstable options from a hashmap.
/// Intended for consuming unstable settings from config files
pub fn from_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, k: &str, v: Option<&str>) -> CargoResult<()> {
fn parse_bool(key: &str, value: Option<&str>) -> CargoResult<bool> {
match value {
None | Some("yes") => Ok(true),
Expand Down

0 comments on commit 1cea4cb

Please sign in to comment.