Avoid a level of indirection for augment_*subcommand

This commit is contained in:
Luca Barbato 2020-11-08 11:55:33 +01:00
parent 77e4e65e31
commit 7a5c12e79a

View file

@ -33,9 +33,10 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
Sp::call_site(DEFAULT_ENV_CASING),
);
let augment_subcommands = gen_augment("augment_subcommands", &e.variants, &attrs, false);
let augment_update_subcommands =
gen_augment("augment_update_subcommands", &e.variants, &attrs, true);
let from_subcommand = gen_from_subcommand(name, &e.variants, &attrs);
let augment_subcommands = gen_augment_subcommands(&e.variants, &attrs);
let augment_update_subcommands = gen_augment_update_subcommands(&e.variants, &attrs);
let update_from_subcommand = gen_update_from_subcommand(name, &e.variants, &attrs);
quote! {
@ -60,25 +61,6 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
}
}
fn gen_augment_subcommands(
variants: &Punctuated<Variant, Token![,]>,
parent_attribute: &Attrs,
) -> TokenStream {
gen_augment("augment_subcommands", variants, parent_attribute, false)
}
fn gen_augment_update_subcommands(
variants: &Punctuated<Variant, Token![,]>,
parent_attribute: &Attrs,
) -> TokenStream {
gen_augment(
"augment_update_subcommands",
variants,
parent_attribute,
true,
)
}
fn gen_augment(
fn_name: &str,
variants: &Punctuated<Variant, Token![,]>,