mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Test rust regression
This commit is contained in:
parent
0242afee81
commit
56aeb155e1
2 changed files with 31 additions and 30 deletions
|
@ -43,11 +43,11 @@ pub fn gen_for_struct(
|
|||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::FromArgMatches for #struct_name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
fn from_arg_matches(arg_matches: &::clap::ArgMatches) -> Self {
|
||||
#struct_name #constructor
|
||||
}
|
||||
|
||||
fn update_from_arg_matches(&mut self, matches: &::clap::ArgMatches) {
|
||||
fn update_from_arg_matches(&mut self, arg_matches: &::clap::ArgMatches) {
|
||||
#updater
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +69,11 @@ pub fn gen_for_enum(name: &Ident) -> TokenStream {
|
|||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::FromArgMatches for #name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
<#name as ::clap::Subcommand>::from_subcommand(matches.subcommand()).unwrap()
|
||||
fn from_arg_matches(arg_matches: &::clap::ArgMatches) -> Self {
|
||||
<#name as ::clap::Subcommand>::from_subcommand(arg_matches.subcommand()).unwrap()
|
||||
}
|
||||
fn update_from_arg_matches(&mut self, matches: &::clap::ArgMatches) {
|
||||
<#name as ::clap::Subcommand>::update_from_subcommand(self, matches.subcommand());
|
||||
fn update_from_arg_matches(&mut self, arg_matches: &::clap::ArgMatches) {
|
||||
<#name as ::clap::Subcommand>::update_from_subcommand(self, arg_matches.subcommand());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,11 +136,11 @@ fn gen_parsers(
|
|||
Ty::Bool => {
|
||||
if update.is_some() {
|
||||
quote_spanned! { ty.span()=>
|
||||
*#field_name || matches.is_present(#name)
|
||||
*#field_name || arg_matches.is_present(#name)
|
||||
}
|
||||
} else {
|
||||
quote_spanned! { ty.span()=>
|
||||
matches.is_present(#name)
|
||||
arg_matches.is_present(#name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,22 +153,22 @@ fn gen_parsers(
|
|||
}
|
||||
|
||||
quote_spanned! { ty.span()=>
|
||||
matches.#value_of(#name)
|
||||
arg_matches.#value_of(#name)
|
||||
.map(#parse)
|
||||
}
|
||||
}
|
||||
|
||||
Ty::OptionOption => quote_spanned! { ty.span()=>
|
||||
if matches.is_present(#name) {
|
||||
Some(matches.#value_of(#name).map(#parse))
|
||||
if arg_matches.is_present(#name) {
|
||||
Some(arg_matches.#value_of(#name).map(#parse))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
|
||||
Ty::OptionVec => quote_spanned! { ty.span()=>
|
||||
if matches.is_present(#name) {
|
||||
Some(matches.#values_of(#name)
|
||||
if arg_matches.is_present(#name) {
|
||||
Some(arg_matches.#values_of(#name)
|
||||
.map(|v| v.map(#parse).collect())
|
||||
.unwrap_or_else(Vec::new))
|
||||
} else {
|
||||
|
@ -184,18 +184,18 @@ fn gen_parsers(
|
|||
}
|
||||
|
||||
quote_spanned! { ty.span()=>
|
||||
matches.#values_of(#name)
|
||||
arg_matches.#values_of(#name)
|
||||
.map(|v| v.map(#parse).collect())
|
||||
.unwrap_or_else(Vec::new)
|
||||
}
|
||||
}
|
||||
|
||||
Ty::Other if occurrences => quote_spanned! { ty.span()=>
|
||||
#parse(matches.#value_of(#name))
|
||||
#parse(arg_matches.#value_of(#name))
|
||||
},
|
||||
|
||||
Ty::Other if flag => quote_spanned! { ty.span()=>
|
||||
#parse(matches.is_present(#name))
|
||||
#parse(arg_matches.is_present(#name))
|
||||
},
|
||||
|
||||
Ty::Other => {
|
||||
|
@ -204,7 +204,7 @@ fn gen_parsers(
|
|||
}
|
||||
|
||||
quote_spanned! { ty.span()=>
|
||||
matches.#value_of(#name)
|
||||
arg_matches.#value_of(#name)
|
||||
.map(#parse)
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ fn gen_parsers(
|
|||
|
||||
if let Some(access) = update {
|
||||
quote_spanned! { field.span()=>
|
||||
if matches.is_present(#name) {
|
||||
if arg_matches.is_present(#name) {
|
||||
#access
|
||||
*#field_name = #field_value
|
||||
}
|
||||
|
@ -249,14 +249,14 @@ pub fn gen_constructor(fields: &Punctuated<Field, Comma>, parent_attribute: &Att
|
|||
};
|
||||
quote_spanned! { kind.span()=>
|
||||
#field_name: {
|
||||
<#subcmd_type as ::clap::Subcommand>::from_subcommand(matches.subcommand())
|
||||
<#subcmd_type as ::clap::Subcommand>::from_subcommand(arg_matches.subcommand())
|
||||
#unwrapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kind::Flatten => quote_spanned! { kind.span()=>
|
||||
#field_name: ::clap::FromArgMatches::from_arg_matches(matches)
|
||||
#field_name: ::clap::FromArgMatches::from_arg_matches(arg_matches)
|
||||
},
|
||||
|
||||
Kind::Skip(val) => match val {
|
||||
|
@ -329,7 +329,7 @@ pub fn gen_updater(
|
|||
|
||||
quote_spanned! { kind.span()=>
|
||||
{
|
||||
let subcmd = matches.subcommand();
|
||||
let subcmd = arg_matches.subcommand();
|
||||
#access
|
||||
#updater
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ pub fn gen_updater(
|
|||
|
||||
Kind::Flatten => quote_spanned! { kind.span()=> {
|
||||
#access
|
||||
::clap::FromArgMatches::update_from_arg_matches(#field_name, matches);
|
||||
::clap::FromArgMatches::update_from_arg_matches(#field_name, arg_matches);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -240,13 +240,13 @@ fn gen_from_subcommand(
|
|||
Unit => quote!(),
|
||||
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
|
||||
let ty = &fields.unnamed[0];
|
||||
quote!( ( <#ty as ::clap::FromArgMatches>::from_arg_matches(matches) ) )
|
||||
quote!( ( <#ty as ::clap::FromArgMatches>::from_arg_matches(arg_matches) ) )
|
||||
}
|
||||
Unnamed(..) => abort_call_site!("{}: tuple enums are not supported", variant.ident),
|
||||
};
|
||||
|
||||
quote! {
|
||||
Some((#sub_name, matches)) => {
|
||||
Some((#sub_name, arg_matches)) => {
|
||||
Some(#name :: #variant_name #constructor_block)
|
||||
}
|
||||
}
|
||||
|
@ -273,11 +273,11 @@ fn gen_from_subcommand(
|
|||
Some((span, var_name, str_ty, values_of)) => quote_spanned! { span=>
|
||||
None => ::std::option::Option::None,
|
||||
|
||||
Some((external, matches)) => {
|
||||
Some((external, arg_matches)) => {
|
||||
::std::option::Option::Some(#name::#var_name(
|
||||
::std::iter::once(#str_ty::from(external))
|
||||
.chain(
|
||||
matches.#values_of("").into_iter().flatten().map(#str_ty::from)
|
||||
arg_matches.#values_of("").into_iter().flatten().map(#str_ty::from)
|
||||
)
|
||||
.collect::<::std::vec::Vec<_>>()
|
||||
))
|
||||
|
@ -361,7 +361,8 @@ fn gen_update_from_subcommand(
|
|||
(
|
||||
quote!((ref mut arg)),
|
||||
quote!(::clap::FromArgMatches::update_from_arg_matches(
|
||||
arg, matches
|
||||
arg,
|
||||
arg_matches
|
||||
)),
|
||||
)
|
||||
} else {
|
||||
|
@ -384,7 +385,7 @@ fn gen_update_from_subcommand(
|
|||
(
|
||||
quote!((ref mut arg)),
|
||||
quote! {
|
||||
<#ty as ::clap::Subcommand>::update_from_subcommand(arg, Some((name, matches)));
|
||||
<#ty as ::clap::Subcommand>::update_from_subcommand(arg, Some((name, arg_matches)));
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -403,11 +404,11 @@ fn gen_update_from_subcommand(
|
|||
&mut self,
|
||||
subcommand: Option<(&str, &::clap::ArgMatches)>
|
||||
) {
|
||||
if let Some((name, matches)) = subcommand {
|
||||
if let Some((name, arg_matches)) = subcommand {
|
||||
match (name, self) {
|
||||
#( #subcommands ),*
|
||||
#( #child_subcommands ),*
|
||||
(_, s) => if let Some(sub) = <Self as ::clap::Subcommand>::from_subcommand(Some((name, matches))) {
|
||||
(_, s) => if let Some(sub) = <Self as ::clap::Subcommand>::from_subcommand(Some((name, arg_matches))) {
|
||||
*s = sub;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue