diff --git a/interactive-clap-derive/src/derives/interactive_clap/mod.rs b/interactive-clap-derive/src/derives/interactive_clap/mod.rs index 271bc67..8124376 100644 --- a/interactive-clap-derive/src/derives/interactive_clap/mod.rs +++ b/interactive-clap-derive/src/derives/interactive_clap/mod.rs @@ -199,8 +199,12 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { <#cli_name as clap::Parser>::parse() } - pub fn try_parse_from(s: &str) -> Result<#cli_name, clap::Error> { - <#cli_name as clap::Parser>::try_parse_from(s.split(" ")) + pub fn try_parse_from(itr: I) -> Result<#cli_name, clap::Error> + where + I: ::std::iter::IntoIterator, + T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone, + { + <#cli_name as clap::Parser>::try_parse_from(itr) } } @@ -337,8 +341,12 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { <#cli_name as clap::Parser>::parse() } - pub fn try_parse_from(s: &str) -> Result<#cli_name, clap::Error> { - <#cli_name as clap::Parser>::try_parse_from(s.split(" ")) + pub fn try_parse_from(itr: I) -> Result<#cli_name, clap::Error> + where + I: ::std::iter::IntoIterator, + T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone, + { + <#cli_name as clap::Parser>::try_parse_from(itr) } } } diff --git a/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__flag.snap b/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__flag.snap index 128cfcb..5dcb81d 100644 --- a/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__flag.snap +++ b/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__flag.snap @@ -30,7 +30,7 @@ impl interactive_clap::FromCli for Args { where Self: Sized + interactive_clap::ToCli, { - let mut clap_variant = optional_clap_variant.unwrap_or_default(); + let mut clap_variant = optional_clap_variant.clone().unwrap_or_default(); let offline = clap_variant.offline.clone(); let new_context_scope = InteractiveClapContextScopeForArgs { offline: offline.into(), @@ -49,12 +49,19 @@ impl Args { Err(err) => Err(err.into()), } } - fn try_parse() -> Result { + pub fn try_parse() -> Result { ::try_parse() } - fn parse() -> CliArgs { + pub fn parse() -> CliArgs { ::parse() } + pub fn try_parse_from(itr: I) -> Result + where + I: ::std::iter::IntoIterator, + T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone, + { + ::try_parse_from(itr) + } } impl From for CliArgs { fn from(args: Args) -> Self { @@ -63,4 +70,3 @@ impl From for CliArgs { } } } - diff --git a/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__simple_struct.snap b/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__simple_struct.snap index f5a3daf..8b00ce9 100644 --- a/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__simple_struct.snap +++ b/interactive-clap-derive/src/tests/snapshots/interactive_clap_derive__tests__test_simple_struct__simple_struct.snap @@ -33,7 +33,7 @@ impl interactive_clap::FromCli for Args { where Self: Sized + interactive_clap::ToCli, { - let mut clap_variant = optional_clap_variant.unwrap_or_default(); + let mut clap_variant = optional_clap_variant.clone().unwrap_or_default(); if clap_variant.age.is_none() { clap_variant .age = match Self::input_age(&context) { @@ -112,12 +112,19 @@ impl Args { Err(err) => Err(err.into()), } } - fn try_parse() -> Result { + pub fn try_parse() -> Result { ::try_parse() } - fn parse() -> CliArgs { + pub fn parse() -> CliArgs { ::parse() } + pub fn try_parse_from(itr: I) -> Result + where + I: ::std::iter::IntoIterator, + T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone, + { + ::try_parse_from(itr) + } } impl From for CliArgs { fn from(args: Args) -> Self { @@ -128,4 +135,3 @@ impl From for CliArgs { } } } -