mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 15:22:30 +00:00
allow for optional subcommands (texitoi/structopt#1)
This commit is contained in:
parent
baa96165f1
commit
91e2d28e81
1 changed files with 7 additions and 1 deletions
|
@ -447,7 +447,13 @@ fn gen_from_subcommand(name: &Ident, variants: &[Variant]) -> quote::Tokens {
|
|||
}
|
||||
|
||||
fn impl_structopt_for_struct(name: &Ident, fields: &[Field], attrs: &[Attribute]) -> quote::Tokens {
|
||||
let subcmd_required = fields.iter().any(is_subcommand);
|
||||
let subcmd_required = fields.iter().any(|field| {
|
||||
let cur_type = ty(&field.ty);
|
||||
match cur_type {
|
||||
Ty::Option => false,
|
||||
_ => is_subcommand(field)
|
||||
}
|
||||
});
|
||||
let clap = gen_clap(attrs, subcmd_required);
|
||||
let augment_clap = gen_augment_clap(fields);
|
||||
let from_clap = gen_from_clap(name, fields);
|
||||
|
|
Loading…
Reference in a new issue