summaryrefslogtreecommitdiffstats
path: root/vendor/clap_derive/src/derives
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/clap_derive/src/derives')
-rw-r--r--vendor/clap_derive/src/derives/args.rs45
-rw-r--r--vendor/clap_derive/src/derives/into_app.rs18
-rw-r--r--vendor/clap_derive/src/derives/parser.rs15
-rw-r--r--vendor/clap_derive/src/derives/subcommand.rs47
-rw-r--r--vendor/clap_derive/src/derives/value_enum.rs9
5 files changed, 84 insertions, 50 deletions
diff --git a/vendor/clap_derive/src/derives/args.rs b/vendor/clap_derive/src/derives/args.rs
index e8611b6bd..20164ff2e 100644
--- a/vendor/clap_derive/src/derives/args.rs
+++ b/vendor/clap_derive/src/derives/args.rs
@@ -16,7 +16,7 @@ use proc_macro2::{Ident, Span, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::{
punctuated::Punctuated, spanned::Spanned, token::Comma, Data, DataStruct, DeriveInput, Field,
- Fields, Generics,
+ Fields, FieldsNamed, Generics,
};
use crate::item::{Item, Kind, Name};
@@ -32,14 +32,7 @@ pub fn derive_args(input: &DeriveInput) -> Result<TokenStream, syn::Error> {
}) => {
let name = Name::Derived(ident.clone());
let item = Item::from_args_struct(input, name)?;
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(&item, fields)?;
gen_for_struct(&item, ident, &input.generics, &fields)
}
Data::Struct(DataStruct {
@@ -93,7 +86,13 @@ pub fn gen_for_struct(
};
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -106,6 +105,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -128,7 +128,13 @@ pub fn gen_for_struct(
}
}
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -141,6 +147,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
fn group_id() -> Option<clap::Id> {
#group_id
@@ -710,7 +717,7 @@ fn gen_parsers(
Ty::Other => {
quote_spanned! { ty.span()=>
#arg_matches.#get_one(#id)
- .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))?
+ .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, concat!("The following required argument was not provided: ", #id)))?
}
}
};
@@ -740,3 +747,17 @@ pub fn raw_deprecated() -> TokenStream {
}
}
+
+pub fn collect_args_fields<'a>(
+ item: &'a Item,
+ fields: &'a FieldsNamed,
+) -> Result<Vec<(&'a Field, Item)>, syn::Error> {
+ fields
+ .named
+ .iter()
+ .map(|field| {
+ let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
+ Ok((field, item))
+ })
+ .collect()
+}
diff --git a/vendor/clap_derive/src/derives/into_app.rs b/vendor/clap_derive/src/derives/into_app.rs
index 72f081fd8..0bd636245 100644
--- a/vendor/clap_derive/src/derives/into_app.rs
+++ b/vendor/clap_derive/src/derives/into_app.rs
@@ -29,7 +29,13 @@ pub fn gen_for_struct(
let app_var = Ident::new("__clap_app", Span::call_site());
let tokens = quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -42,6 +48,7 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name);
@@ -69,7 +76,13 @@ pub fn gen_for_enum(
let app_var = Ident::new("__clap_app", Span::call_site());
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -82,6 +95,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name)
diff --git a/vendor/clap_derive/src/derives/parser.rs b/vendor/clap_derive/src/derives/parser.rs
index 39b0b8a77..272948b63 100644
--- a/vendor/clap_derive/src/derives/parser.rs
+++ b/vendor/clap_derive/src/derives/parser.rs
@@ -21,6 +21,7 @@ use syn::{
Generics,
};
+use crate::derives::args::collect_args_fields;
use crate::derives::{args, into_app, subcommand};
use crate::item::Item;
use crate::item::Name;
@@ -36,14 +37,7 @@ pub fn derive_parser(input: &DeriveInput) -> Result<TokenStream, syn::Error> {
}) => {
let name = Name::Assigned(quote!(#pkg_name));
let item = Item::from_args_struct(input, name)?;
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(&item, fields)?;
gen_for_struct(&item, ident, &input.generics, &fields)
}
Data::Struct(DataStruct {
@@ -92,6 +86,10 @@ fn gen_for_struct(
let args = args::gen_for_struct(item, item_name, generics, fields)?;
Ok(quote! {
+ #[automatically_derived]
+ #[allow(
+ unused_qualifications,
+ )]
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
#into_app
@@ -111,6 +109,7 @@ fn gen_for_enum(
let subcommand = subcommand::gen_for_enum(item, item_name, generics, variants)?;
Ok(quote! {
+ #[automatically_derived]
impl #impl_generics clap::Parser for #item_name #ty_generics #where_clause {}
#into_app
diff --git a/vendor/clap_derive/src/derives/subcommand.rs b/vendor/clap_derive/src/derives/subcommand.rs
index 403fe4557..3ae74d01a 100644
--- a/vendor/clap_derive/src/derives/subcommand.rs
+++ b/vendor/clap_derive/src/derives/subcommand.rs
@@ -17,6 +17,7 @@ use quote::{format_ident, quote, quote_spanned};
use syn::{spanned::Spanned, Data, DeriveInput, FieldsUnnamed, Generics, Variant};
use crate::derives::args;
+use crate::derives::args::collect_args_fields;
use crate::item::{Item, Kind, Name};
use crate::utils::{is_simple_ty, subty_if_name};
@@ -65,7 +66,13 @@ pub fn gen_for_enum(
let has_subcommand = gen_has_subcommand(variants)?;
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -78,6 +85,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -91,7 +99,13 @@ pub fn gen_for_enum(
#update_from_arg_matches
}
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -104,6 +118,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
fn augment_subcommands <'b>(__clap_app: clap::Command) -> clap::Command {
#augmentation
@@ -264,15 +279,7 @@ fn gen_augment(
let sub_augment = match variant.fields {
Named(ref fields) => {
// Defer to `gen_augment` for adding cmd methods
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item =
- Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
args::gen_augment(&fields, &subcommand_var, item, override_required)?
}
Unit => {
@@ -484,14 +491,7 @@ fn gen_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStream, sy
let variant_name = &variant.ident;
let constructor_block = match variant.fields {
Named(ref fields) => {
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
args::gen_constructor(&fields)?
},
Unit => quote!(),
@@ -599,14 +599,7 @@ fn gen_update_from_arg_matches(variants: &[(&Variant, Item)]) -> Result<TokenStr
let field_names = fields.named.iter().map(|field| {
field.ident.as_ref().unwrap()
}).collect::<Vec<_>>();
- let fields = fields
- .named
- .iter()
- .map(|field| {
- let item = Item::from_args_field(field, item.casing(), item.env_casing())?;
- Ok((field, item))
- })
- .collect::<Result<Vec<_>, syn::Error>>()?;
+ let fields = collect_args_fields(item, fields)?;
let update = args::gen_updater(&fields, false)?;
(quote!( { #( #field_names, )* }), quote!( { #update } ))
}
diff --git a/vendor/clap_derive/src/derives/value_enum.rs b/vendor/clap_derive/src/derives/value_enum.rs
index 6f107c01c..397eb3323 100644
--- a/vendor/clap_derive/src/derives/value_enum.rs
+++ b/vendor/clap_derive/src/derives/value_enum.rs
@@ -51,7 +51,13 @@ pub fn gen_for_enum(
let to_possible_value = gen_to_possible_value(item, &lits);
Ok(quote! {
- #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
+ #[allow(
+ dead_code,
+ unreachable_code,
+ unused_variables,
+ unused_braces,
+ unused_qualifications,
+ )]
#[allow(
clippy::style,
clippy::complexity,
@@ -64,6 +70,7 @@ pub fn gen_for_enum(
clippy::suspicious_else_formatting,
clippy::almost_swapped,
)]
+ #[automatically_derived]
impl clap::ValueEnum for #item_name {
#value_variants
#to_possible_value