mirror of
https://github.com/Drop-OSS/interactive-clap.git
synced 2026-01-30 20:55:25 +01:00
fix!: Proxy try_parse_from to Clap's try_parse_from as is, instead of naive parsing of &str (#21)
`try_parse_from` doesn't have special treatment for quotes (`command "some thing"` is split into 3 arguments).
This commit is contained in:
@@ -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<I, T>(itr: I) -> Result<#cli_name, clap::Error>
|
||||
where
|
||||
I: ::std::iter::IntoIterator<Item = T>,
|
||||
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<I, T>(itr: I) -> Result<#cli_name, clap::Error>
|
||||
where
|
||||
I: ::std::iter::IntoIterator<Item = T>,
|
||||
T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone,
|
||||
{
|
||||
<#cli_name as clap::Parser>::try_parse_from(itr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<CliArgs, clap::Error> {
|
||||
pub fn try_parse() -> Result<CliArgs, clap::Error> {
|
||||
<CliArgs as clap::Parser>::try_parse()
|
||||
}
|
||||
fn parse() -> CliArgs {
|
||||
pub fn parse() -> CliArgs {
|
||||
<CliArgs as clap::Parser>::parse()
|
||||
}
|
||||
pub fn try_parse_from<I, T>(itr: I) -> Result<CliArgs, clap::Error>
|
||||
where
|
||||
I: ::std::iter::IntoIterator<Item = T>,
|
||||
T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone,
|
||||
{
|
||||
<CliArgs as clap::Parser>::try_parse_from(itr)
|
||||
}
|
||||
}
|
||||
impl From<Args> for CliArgs {
|
||||
fn from(args: Args) -> Self {
|
||||
@@ -63,4 +70,3 @@ impl From<Args> for CliArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CliArgs, clap::Error> {
|
||||
pub fn try_parse() -> Result<CliArgs, clap::Error> {
|
||||
<CliArgs as clap::Parser>::try_parse()
|
||||
}
|
||||
fn parse() -> CliArgs {
|
||||
pub fn parse() -> CliArgs {
|
||||
<CliArgs as clap::Parser>::parse()
|
||||
}
|
||||
pub fn try_parse_from<I, T>(itr: I) -> Result<CliArgs, clap::Error>
|
||||
where
|
||||
I: ::std::iter::IntoIterator<Item = T>,
|
||||
T: ::std::convert::Into<::std::ffi::OsString> + ::std::clone::Clone,
|
||||
{
|
||||
<CliArgs as clap::Parser>::try_parse_from(itr)
|
||||
}
|
||||
}
|
||||
impl From<Args> for CliArgs {
|
||||
fn from(args: Args) -> Self {
|
||||
@@ -128,4 +135,3 @@ impl From<Args> for CliArgs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user