mirror of
https://github.com/starship/starship.git
synced 2026-06-22 02:02:12 +07:00
feat(config): warn about unknown config key names (#2527)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user