diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-05 20:26:52 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-10 00:47:41 +0100 |
commit | d936b611fc0e7ee48c4ad79671d6b1aec25212c3 (patch) | |
tree | 7a305bacfd42c208a8926fb448cdc910e5f089d5 /lib/core/libimagrt/src | |
parent | 0f32471a03601c50b600ab30d9d83f0c41268038 (diff) |
Fix config override mechanism
The bug was that we did not actually _set_ the new value.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/core/libimagrt/src')
-rw-r--r-- | lib/core/libimagrt/src/configuration.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 73121b01..eb5bf21b 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -111,28 +111,26 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> { use libimagutil::key_value_split::*; use toml_query::read::TomlValueReadExt; - let iter = v.into_iter() + v.into_iter() .map(|s| { debug!("Trying to process '{}'", s); s }) .filter_map(|s| s.into_kv().map(Into::into).or_else(|| { warn!("Could split at '=' - will be ignore override"); None })) .map(|(k, v)| { - let value = val - .read(&k) + let value = val.read_mut(&k) .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) - .map(|v| info!("Successfully overridden: {} = {}", k, v)) - .ok_or_else(|| Error::from(err_msg("Config override type not matching"))) - }); + let new_value = into_value(value, v) + .ok_or_else(|| Error::from(err_msg("Config override type not matching")))?; - for elem in iter { - let _ = elem.context(err_msg("Config override error"))?; - } - - Ok(()) + info!("Successfully overridden: {} = {}", k, new_value); + *value = new_value; + 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`. |