mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(config): allow printing default and computed config (#2521)
* feat: allow printing default and computed config * fix custom modules * actually fix custom modules
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "starship_module_config_derive"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2018"
|
||||
authors = ["Matan Kushner <hello@matchai.me>"]
|
||||
homepage = "https://starship.rs"
|
||||
|
||||
@@ -18,29 +18,20 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream {
|
||||
if let syn::Data::Struct(data) = dinput.data {
|
||||
if let syn::Fields::Named(fields_named) = data.fields {
|
||||
let mut load_tokens = quote! {};
|
||||
let mut from_tokens = quote! {};
|
||||
|
||||
for field in fields_named.named.iter() {
|
||||
let ident = field.ident.as_ref().unwrap();
|
||||
let ty = &field.ty;
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
let new_from_tokens = quote! {
|
||||
#ident: config.get(stringify!(#ident)).and_then(<#ty>::from_config)?,
|
||||
};
|
||||
|
||||
load_tokens = quote! {
|
||||
#load_tokens
|
||||
#new_load_tokens
|
||||
};
|
||||
from_tokens = quote! {
|
||||
#from_tokens
|
||||
#new_from_tokens
|
||||
}
|
||||
}
|
||||
|
||||
load_config = quote! {
|
||||
@@ -60,11 +51,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream {
|
||||
};
|
||||
from_config = quote! {
|
||||
fn from_config(config: &'a toml::Value) -> Option<Self> {
|
||||
let config = config.as_table()?;
|
||||
|
||||
Some(#struct_ident {
|
||||
#from_tokens
|
||||
})
|
||||
Some(Self::default().load_config(config))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user