summaryrefslogtreecommitdiffstats
path: root/vendor/clap_derive/src/derives/into_app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/clap_derive/src/derives/into_app.rs')
-rw-r--r--vendor/clap_derive/src/derives/into_app.rs62
1 files changed, 18 insertions, 44 deletions
diff --git a/vendor/clap_derive/src/derives/into_app.rs b/vendor/clap_derive/src/derives/into_app.rs
index 319735753..a45667ab2 100644
--- a/vendor/clap_derive/src/derives/into_app.rs
+++ b/vendor/clap_derive/src/derives/into_app.rs
@@ -12,36 +12,18 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.
-use std::env;
-
use proc_macro2::{Span, TokenStream};
use quote::quote;
-use syn::{Attribute, Generics, Ident};
+use syn::{Generics, Ident};
-use crate::{
- attrs::{Attrs, Name, DEFAULT_CASING, DEFAULT_ENV_CASING},
- utils::Sp,
-};
+use crate::item::Item;
-pub fn gen_for_struct(
- struct_name: &Ident,
- generics: &Generics,
- attrs: &[Attribute],
-) -> TokenStream {
- let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default();
+pub fn gen_for_struct(item: &Item, item_name: &Ident, generics: &Generics) -> TokenStream {
+ let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
- let attrs = Attrs::from_struct(
- Span::call_site(),
- attrs,
- Name::Assigned(quote!(#app_name)),
- Sp::call_site(DEFAULT_CASING),
- Sp::call_site(DEFAULT_ENV_CASING),
- );
- let name = attrs.cased_name();
+ let name = item.cased_name();
let app_var = Ident::new("__clap_app", Span::call_site());
- let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
-
let tokens = quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
@@ -56,14 +38,13 @@ pub fn gen_for_struct(
clippy::suspicious_else_formatting,
)]
#[deny(clippy::correctness)]
- #[allow(deprecated)]
- impl #impl_generics clap::CommandFactory for #struct_name #ty_generics #where_clause {
- fn into_app<'b>() -> clap::Command<'b> {
+ impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
+ fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name);
<Self as clap::Args>::augment_args(#app_var)
}
- fn into_app_for_update<'b>() -> clap::Command<'b> {
+ fn command_for_update<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name);
<Self as clap::Args>::augment_args_for_update(#app_var)
}
@@ -73,21 +54,12 @@ pub fn gen_for_struct(
tokens
}
-pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute]) -> TokenStream {
- let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default();
+pub fn gen_for_enum(item: &Item, item_name: &Ident, generics: &Generics) -> TokenStream {
+ let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
- let attrs = Attrs::from_struct(
- Span::call_site(),
- attrs,
- Name::Assigned(quote!(#app_name)),
- Sp::call_site(DEFAULT_CASING),
- Sp::call_site(DEFAULT_ENV_CASING),
- );
- let name = attrs.cased_name();
+ let name = item.cased_name();
let app_var = Ident::new("__clap_app", Span::call_site());
- let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
-
quote! {
#[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
#[allow(
@@ -102,17 +74,19 @@ pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute])
clippy::suspicious_else_formatting,
)]
#[deny(clippy::correctness)]
- impl #impl_generics clap::CommandFactory for #enum_name #ty_generics #where_clause {
- fn into_app<'b>() -> clap::Command<'b> {
- #[allow(deprecated)]
+ impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
+ fn command<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name)
- .setting(clap::AppSettings::SubcommandRequiredElseHelp);
+ .subcommand_required(true)
+ .arg_required_else_help(true);
<Self as clap::Subcommand>::augment_subcommands(#app_var)
}
- fn into_app_for_update<'b>() -> clap::Command<'b> {
+ fn command_for_update<'b>() -> clap::Command {
let #app_var = clap::Command::new(#name);
<Self as clap::Subcommand>::augment_subcommands_for_update(#app_var)
+ .subcommand_required(false)
+ .arg_required_else_help(false)
}
}
}