Skip to content

Commit

Permalink
feat: Impl update_from_arg_matches_mut for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ysndr committed Aug 25, 2024
1 parent 359edc2 commit 8c3b3b0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion clap_derive/src/derives/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub(crate) fn gen_for_enum(
let mut augmentations_update = TokenStream::default();

let mut constructors = TokenStream::default();
let mut updaters = TokenStream::default();

for (item, variant) in variants.iter() {
let Fields::Named(ref fields) = variant.fields else {
Expand Down Expand Up @@ -128,6 +129,23 @@ pub(crate) fn gen_for_enum(
};

constructors.extend(constructor);

let genned_updater = gen_updater(&fields, false)?;

let field_names = fields
.iter()
.map(|(field, _)| field.ident.as_ref().unwrap());
let updater = quote! {

if __clap_arg_matches.contains_id(#group_id) {
let #item_name::#variant_name { #( #field_names ),* } = self else {
unreachable!();
};
#genned_updater;
}
};

updaters.extend(updater);
}

let raw_deprecated = raw_deprecated();
Expand Down Expand Up @@ -171,7 +189,7 @@ pub(crate) fn gen_for_enum(

fn update_from_arg_matches_mut(&mut self, __clap_arg_matches: &mut clap::ArgMatches) -> ::std::result::Result<(), clap::Error> {
#raw_deprecated
// #updater
#updaters
::std::result::Result::Ok(())
}
}
Expand Down

0 comments on commit 8c3b3b0

Please sign in to comment.