mirror of
https://github.com/Drop-OSS/interactive-clap.git
synced 2026-01-30 20:55:25 +01:00
fixed from_cli_arg
This commit is contained in:
@@ -106,21 +106,13 @@ fn fields_value(field: &syn::Field) -> proc_macro2::TokenStream {
|
||||
},
|
||||
_ => String::new(),
|
||||
};
|
||||
if let "Option" = type_string.as_str() {
|
||||
quote! {
|
||||
let #ident_field = optional_clap_variant
|
||||
.as_ref()
|
||||
.and_then(|clap_variant| clap_variant.#ident_field.clone());
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
let #ident_field = Self::#fn_from_cli_arg(
|
||||
optional_clap_variant
|
||||
.clone()
|
||||
.and_then(|clap_variant| clap_variant.#ident_field),
|
||||
&context,
|
||||
)?;
|
||||
}
|
||||
quote! {
|
||||
let #ident_field = Self::#fn_from_cli_arg(
|
||||
optional_clap_variant
|
||||
.clone()
|
||||
.and_then(|clap_variant| clap_variant.#ident_field),
|
||||
&context,
|
||||
)?;
|
||||
}
|
||||
} else {
|
||||
quote!()
|
||||
|
||||
@@ -60,14 +60,36 @@ pub fn from_cli_arg(ast: &syn::DeriveInput, fields: &syn::Fields) -> Vec<proc_ma
|
||||
let cli_field_type = super::cli_field_type::cli_field_type(ty);
|
||||
let fn_input_arg =
|
||||
syn::Ident::new(&format!("input_{}", &ident_field), Span::call_site());
|
||||
quote! {
|
||||
fn #fn_from_cli_arg(
|
||||
#optional_cli_field_name: #cli_field_type,
|
||||
context: &#input_context_dir,
|
||||
) -> color_eyre::eyre::Result<#ty> {
|
||||
match #optional_cli_field_name {
|
||||
Some(#ident_field) => Ok(#ident_field),
|
||||
None => Self::#fn_input_arg(&context),
|
||||
|
||||
let type_string = match &ty {
|
||||
syn::Type::Path(type_path) => match type_path.path.segments.last() {
|
||||
Some(path_segment) => path_segment.ident.to_string(),
|
||||
_ => String::new(),
|
||||
},
|
||||
_ => String::new(),
|
||||
};
|
||||
if let "Option" = type_string.as_str() {
|
||||
quote! {
|
||||
fn #fn_from_cli_arg(
|
||||
#optional_cli_field_name: #cli_field_type,
|
||||
context: &#input_context_dir,
|
||||
) -> color_eyre::eyre::Result<#ty> {
|
||||
match #optional_cli_field_name {
|
||||
Some(#ident_field) => Ok(Some(#ident_field)),
|
||||
None => Self::#fn_input_arg(&context),
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
fn #fn_from_cli_arg(
|
||||
#optional_cli_field_name: #cli_field_type,
|
||||
context: &#input_context_dir,
|
||||
) -> color_eyre::eyre::Result<#ty> {
|
||||
match #optional_cli_field_name {
|
||||
Some(#ident_field) => Ok(#ident_field),
|
||||
None => Self::#fn_input_arg(&context),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user