Fix config override mechanism

The bug was that we did not actually _set_ the new value.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-02-05 20:26:52 +01:00
parent 0f32471a03
commit d936b611fc

View file

@ -111,28 +111,26 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> {
use libimagutil::key_value_split::*; use libimagutil::key_value_split::*;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
let iter = v.into_iter() v.into_iter()
.map(|s| { debug!("Trying to process '{}'", s); s }) .map(|s| { debug!("Trying to process '{}'", s); s })
.filter_map(|s| s.into_kv().map(Into::into).or_else(|| { .filter_map(|s| s.into_kv().map(Into::into).or_else(|| {
warn!("Could split at '=' - will be ignore override"); warn!("Could split at '=' - will be ignore override");
None None
})) }))
.map(|(k, v)| { .map(|(k, v)| {
let value = val let value = val.read_mut(&k)
.read(&k)
.context(EM::TomlQueryError)? .context(EM::TomlQueryError)?
.ok_or_else(|| Error::from(err_msg("Confit parser error")))?; .ok_or_else(|| Error::from(err_msg("No config value there, cannot override.")))?;
into_value(value, v) let new_value = into_value(value, v)
.map(|v| info!("Successfully overridden: {} = {}", k, v)) .ok_or_else(|| Error::from(err_msg("Config override type not matching")))?;
.ok_or_else(|| Error::from(err_msg("Config override type not matching")))
});
for elem in iter {
let _ = elem.context(err_msg("Config override error"))?;
}
info!("Successfully overridden: {} = {}", k, new_value);
*value = new_value;
Ok(()) Ok(())
})
.map(|elem: Result<()>| elem.context(err_msg("Config override error")).map_err(Error::from))
.collect::<Result<()>>()
} }
/// Tries to convert the String `s` into the same type as `value`. /// Tries to convert the String `s` into the same type as `value`.