From 7229ca668be1f3e27aa76f1078c44f52751dff32 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Mon, 27 Feb 2023 12:43:59 +0200 Subject: [PATCH] fix(derive): dedup subcommands --- clap_derive/src/derives/subcommand.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs index 8a44e0c42196..c2641815d76a 100644 --- a/clap_derive/src/derives/subcommand.rs +++ b/clap_derive/src/derives/subcommand.rs @@ -255,13 +255,11 @@ fn gen_augment( let subcommand = quote! { let #app_var = #app_var.subcommand({ #deprecations; - let #subcommand_var = clap::Command::new(#name); - let #subcommand_var = #subcommand_var + let #subcommand_var = clap::Command::new(#name) .subcommand_required(true) - .arg_required_else_help(true); - let #subcommand_var = #subcommand_var #initial_app_methods; - let #subcommand_var = #arg_block; - #subcommand_var #final_from_attrs #override_methods + .arg_required_else_help(true) + #initial_app_methods; + #arg_block #final_from_attrs #override_methods }); }; Some(subcommand) @@ -283,13 +281,12 @@ fn gen_augment( args::gen_augment(&fields, &subcommand_var, item, override_required) } Unit => { - let arg_block = quote!( #subcommand_var ); let initial_app_methods = item.initial_top_level_methods(); let final_from_attrs = item.final_top_level_methods(); quote! { - let #subcommand_var = #subcommand_var #initial_app_methods; - let #subcommand_var = #arg_block; - #subcommand_var #final_from_attrs + #subcommand_var + #initial_app_methods + #final_from_attrs } }, Unnamed(FieldsUnnamed { ref unnamed, .. }) if unnamed.len() == 1 => {