From ebf9c16a23fdb4f23fdc354b1d16bb5a42dd9ee6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 2 Jun 2022 14:58:38 -0500 Subject: [PATCH] refactor(derive): Clarify functions role --- clap_derive/src/attrs.rs | 2 +- clap_derive/src/derives/args.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index c9f1979c..dbe8115b 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -721,7 +721,7 @@ impl Attrs { .unwrap_or_else(|| self.parser(field_type).value_parser()) } - pub fn custom_value_parser(&self) -> bool { + pub fn ignore_parser(&self) -> bool { self.value_parser.is_some() } diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index afd90c60..54ef3999 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -251,7 +251,7 @@ pub fn gen_augment( let func = &parser.func; let validator = match *parser.kind { - _ if attrs.custom_value_parser() || attrs.is_enum() => quote!(), + _ if attrs.ignore_parser() || attrs.is_enum() => quote!(), ParserKind::TryFromStr => quote_spanned! { func.span()=> .validator(|s| { #func(s) @@ -268,7 +268,7 @@ pub fn gen_augment( }; let value_name = attrs.value_name(); - let possible_values = if attrs.is_enum() && !attrs.custom_value_parser() { + let possible_values = if attrs.is_enum() && !attrs.ignore_parser() { gen_arg_enum_possible_values(convert_type) } else { quote!() @@ -537,7 +537,7 @@ fn gen_parsers( quote!(|s| ::std::ops::Deref::deref(s)), func.clone(), ), - _ if attrs.custom_value_parser() => ( + _ if attrs.ignore_parser() => ( quote_spanned!(span=> remove_one::<#convert_type>), quote_spanned!(span=> remove_many::<#convert_type>), quote!(|s| s), @@ -568,7 +568,7 @@ fn gen_parsers( quote_spanned!(func.span()=> |s| #func(s).map_err(|err| clap::Error::raw(clap::ErrorKind::ValueValidation, format!("Invalid value for {}: {}", #id, err)))), ), }; - if attrs.is_enum() && !attrs.custom_value_parser() { + if attrs.is_enum() && !attrs.ignore_parser() { let ci = attrs.ignore_case(); parse = quote_spanned! { convert_type.span()=>