diff --git a/interactive-clap-derive/src/derives/interactive_clap/methods/from_cli_for_struct.rs b/interactive-clap-derive/src/derives/interactive_clap/methods/from_cli_for_struct.rs index a43619e..aaa8488 100644 --- a/interactive-clap-derive/src/derives/interactive_clap/methods/from_cli_for_struct.rs +++ b/interactive-clap-derive/src/derives/interactive_clap/methods/from_cli_for_struct.rs @@ -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!() diff --git a/interactive-clap-derive/src/derives/interactive_clap/methods/get_arg_from_cli_for_struct.rs b/interactive-clap-derive/src/derives/interactive_clap/methods/get_arg_from_cli_for_struct.rs index 36aec20..830399b 100644 --- a/interactive-clap-derive/src/derives/interactive_clap/methods/get_arg_from_cli_for_struct.rs +++ b/interactive-clap-derive/src/derives/interactive_clap/methods/get_arg_from_cli_for_struct.rs @@ -60,14 +60,36 @@ pub fn from_cli_arg(ast: &syn::DeriveInput, fields: &syn::Fields) -> Vec 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), + } } } }