From 2ff14448863ac1a1dd9533461708e29aae170c2d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:06:31 +0200 Subject: Adding debian version 1.65.0+dfsg1-2. Signed-off-by: Daniel Baumann --- vendor/clap_derive/src/attrs.rs | 159 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 156 insertions(+), 3 deletions(-) (limited to 'vendor/clap_derive/src/attrs.rs') diff --git a/vendor/clap_derive/src/attrs.rs b/vendor/clap_derive/src/attrs.rs index 3c685fbe8..2c5b47d95 100644 --- a/vendor/clap_derive/src/attrs.rs +++ b/vendor/clap_derive/src/attrs.rs @@ -450,7 +450,7 @@ impl Attrs { } fn push_method(&mut self, name: Ident, arg: impl ToTokens) { - if name == "name" { + if name == "name" || name == "id" { self.name = Name::Assigned(quote!(#arg)); } else if name == "value_parser" { self.value_parser = Some(ValueParser::Explicit(Method::new(name, quote!(#arg)))); @@ -552,7 +552,7 @@ impl Attrs { }) } else { quote_spanned!(ident.span()=> { - static DEFAULT_VALUE: clap::once_cell::sync::Lazy = clap::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy = clap::__macro_refs::once_cell::sync::Lazy::new(|| { let val: #ty = #val; ::std::string::ToString::to_string(&val) }); @@ -564,6 +564,81 @@ impl Attrs { self.methods.push(Method::new(raw_ident, val)); } + DefaultValuesT(ident, expr) => { + let ty = if let Some(ty) = self.ty.as_ref() { + ty + } else { + abort!( + ident, + "#[clap(default_values_t)] (without an argument) can be used \ + only on field level"; + + note = "see \ + https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#magic-attributes") + }; + + let container_type = Ty::from_syn_ty(ty); + if *container_type != Ty::Vec { + abort!( + ident, + "#[clap(default_values_t)] can be used only on Vec types"; + + note = "see \ + https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#magic-attributes") + } + let inner_type = inner_type(ty); + + // Use `Borrow<#inner_type>` so we accept `&Vec<#inner_type>` and + // `Vec<#inner_type>`. + let val = if parsed.iter().any(|a| matches!(a, ValueEnum(_))) { + quote_spanned!(ident.span()=> { + { + fn iter_to_vals(iterable: impl IntoIterator) -> Vec<&'static str> + where + T: ::std::borrow::Borrow<#inner_type> + { + iterable + .into_iter() + .map(|val| { + clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name() + }) + .collect() + + } + + static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + iter_to_vals(#expr) + }); + &*DEFAULT_VALUES.as_slice() + } + }) + } else { + quote_spanned!(ident.span()=> { + { + fn iter_to_vals(iterable: impl IntoIterator) -> Vec + where + T: ::std::borrow::Borrow<#inner_type> + { + iterable.into_iter().map(|val| val.borrow().to_string()).collect() + + } + + static DEFAULT_STRINGS: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + iter_to_vals(#expr) + }); + + static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect() + }); + &*DEFAULT_VALUES.as_slice() + } + }) + }; + + self.methods + .push(Method::new(Ident::new("default_values", ident.span()), val)); + } + DefaultValueOsT(ident, expr) => { let ty = if let Some(ty) = self.ty.as_ref() { ty @@ -592,7 +667,7 @@ impl Attrs { }) } else { quote_spanned!(ident.span()=> { - static DEFAULT_VALUE: clap::once_cell::sync::Lazy<::std::ffi::OsString> = clap::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { let val: #ty = #val; ::std::ffi::OsString::from(val) }); @@ -604,6 +679,84 @@ impl Attrs { self.methods.push(Method::new(raw_ident, val)); } + DefaultValuesOsT(ident, expr) => { + let ty = if let Some(ty) = self.ty.as_ref() { + ty + } else { + abort!( + ident, + "#[clap(default_values_os_t)] (without an argument) can be used \ + only on field level"; + + note = "see \ + https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#magic-attributes") + }; + + let container_type = Ty::from_syn_ty(ty); + if *container_type != Ty::Vec { + abort!( + ident, + "#[clap(default_values_os_t)] can be used only on Vec types"; + + note = "see \ + https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#magic-attributes") + } + let inner_type = inner_type(ty); + + // Use `Borrow<#inner_type>` so we accept `&Vec<#inner_type>` and + // `Vec<#inner_type>`. + let val = if parsed.iter().any(|a| matches!(a, ValueEnum(_))) { + quote_spanned!(ident.span()=> { + { + fn iter_to_vals(iterable: impl IntoIterator) -> Vec<&'static ::std::ffi::OsStr> + where + T: ::std::borrow::Borrow<#inner_type> + { + iterable + .into_iter() + .map(|val| { + clap::ValueEnum::to_possible_value(val.borrow()).unwrap().get_name() + }) + .map(::std::ffi::OsStr::new) + .collect() + + } + + static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + iter_to_vals(#expr) + }); + &*DEFAULT_VALUES.as_slice() + } + }) + } else { + quote_spanned!(ident.span()=> { + { + fn iter_to_vals(iterable: impl IntoIterator) -> Vec<::std::ffi::OsString> + where + T: ::std::borrow::Borrow<#inner_type> + { + iterable.into_iter().map(|val| val.borrow().into()).collect() + + } + + static DEFAULT_OS_STRINGS: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + iter_to_vals(#expr) + }); + + static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { + DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect() + }); + &*DEFAULT_VALUES.as_slice() + } + }) + }; + + self.methods.push(Method::new( + Ident::new("default_values_os", ident.span()), + val, + )); + } + NextDisplayOrder(ident, expr) => { self.next_display_order = Some(Method::new(ident, quote!(#expr))); } -- cgit v1.2.3