diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2021-03-31 20:13:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-31 20:13:23 +0200 |
commit | 51972801de888f475d03e968a97ff01f0a2ebd7a (patch) | |
tree | aea722a095caaaa8d97a2784bb0c1f19005b08d3 /src/configs | |
parent | 9d15eb135b7f02662fa5df1a680b635f29d2515b (diff) |
feat(config): warn about unknown config key names (#2527)
Diffstat (limited to 'src/configs')
-rw-r--r-- | src/configs/starship_root.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/configs/starship_root.rs b/src/configs/starship_root.rs index 4d26fd1ca..cefa85075 100644 --- a/src/configs/starship_root.rs +++ b/src/configs/starship_root.rs @@ -1,9 +1,8 @@ -use crate::config::ModuleConfig; +use crate::{config::ModuleConfig, module::ALL_MODULES}; use serde::Serialize; -use starship_module_config_derive::ModuleConfig; -#[derive(Clone, ModuleConfig, Serialize)] +#[derive(Clone, Serialize)] pub struct StarshipRootConfig<'a> { pub format: &'a str, pub scan_timeout: u64, @@ -88,3 +87,27 @@ impl<'a> Default for StarshipRootConfig<'a> { } } } + +impl<'a> ModuleConfig<'a> for StarshipRootConfig<'a> { + fn load_config(&mut self, config: &'a toml::Value) { + if let toml::Value::Table(config) = config { + config.iter().for_each(|(k, v)| match k.as_str() { + "format" => self.format.load_config(v), + "scan_timeout" => self.scan_timeout.load_config(v), + "command_timeout" => self.command_timeout.load_config(v), + "add_newline" => self.add_newline.load_config(v), + unknown => { + if !ALL_MODULES.contains(&unknown) && unknown != "custom" { + log::warn!("Unknown config key '{}'", unknown); + } + } + }); + } + } + + fn from_config(config: &'a toml::Value) -> Option<Self> { + let mut out = Self::default(); + out.load_config(config); + Some(out) + } +} |