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 /starship_module_config_derive | |
parent | 9d15eb135b7f02662fa5df1a680b635f29d2515b (diff) |
feat(config): warn about unknown config key names (#2527)
Diffstat (limited to 'starship_module_config_derive')
-rw-r--r-- | starship_module_config_derive/Cargo.toml | 2 | ||||
-rw-r--r-- | starship_module_config_derive/src/lib.rs | 27 |
2 files changed, 14 insertions, 15 deletions
diff --git a/starship_module_config_derive/Cargo.toml b/starship_module_config_derive/Cargo.toml index 04352616f..642d424ee 100644 --- a/starship_module_config_derive/Cargo.toml +++ b/starship_module_config_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starship_module_config_derive" -version = "0.1.3" +version = "0.2.0" edition = "2018" authors = ["Matan Kushner <hello@matchai.me>"] homepage = "https://starship.rs" diff --git a/starship_module_config_derive/src/lib.rs b/starship_module_config_derive/src/lib.rs index 8594a902a..254b0a3cc 100644 --- a/starship_module_config_derive/src/lib.rs +++ b/starship_module_config_derive/src/lib.rs @@ -23,9 +23,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream { let ident = field.ident.as_ref().unwrap(); let new_load_tokens = quote! { - if let Some(config_str) = config.get(stringify!(#ident)) { - new_module_config.#ident = new_module_config.#ident.load_config(config_str); - } + stringify!(#ident) => self.#ident.load_config(v), }; load_tokens = quote! { @@ -35,23 +33,24 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream { } load_config = quote! { - fn load_config(&self, config: &'a toml::Value) -> Self { - let mut new_module_config = self.clone(); + fn load_config(&mut self, config: &'a toml::Value) { if let toml::Value::Table(config) = config { - if config.get("prefix").is_some() { - log::warn!("\"prefix\" has been removed in favor of \"format\". For more details, see: https://starship.rs/migrating-to-0.45.0/") - } - if config.get("suffix").is_some() { - log::warn!("\"suffix\" has been removed in favor of \"format\". For more details, see: https://starship.rs/migrating-to-0.45.0/") - } - #load_tokens + config.iter().for_each(|(k, v)| { + match k.as_str() { + #load_tokens + unknown => { + ::log::warn!("Unknown config key '{}'", unknown); + }, + } + }); } - new_module_config } }; from_config = quote! { fn from_config(config: &'a toml::Value) -> Option<Self> { - Some(Self::default().load_config(config)) + let mut out = Self::default(); + out.load_config(config); + Some(out) } }; } |