mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
fix(derive): Make mismatched behavior more obvious
If the inner type never implemented `group_id()`, then it won't work and people will be confused. This at least gives people an idea of whats going wrong. This is most likely to be a problem until #3165 is fully implemented but hand-implementations can still run into this. Probably should have made the groups another trait to catch this in type system but too late.
This commit is contained in:
parent
06d2049931
commit
78676f5043
1 changed files with 3 additions and 1 deletions
|
@ -447,7 +447,9 @@ pub fn gen_constructor(fields: &[(&Field, Item)]) -> TokenStream {
|
|||
Ty::Option => {
|
||||
quote_spanned! { kind.span()=>
|
||||
#field_name: {
|
||||
if <#inner_type as clap::Args>::group_id().map(|group_id| #arg_matches.contains_id(group_id.as_str())).unwrap_or(false) {
|
||||
let group_id = <#inner_type as clap::Args>::group_id()
|
||||
.expect("`#[arg(flatten)]`ed field type implements `Args::group_id`");
|
||||
if #arg_matches.contains_id(group_id.as_str()) {
|
||||
Some(
|
||||
<#inner_type as clap::FromArgMatches>::from_arg_matches_mut(#arg_matches)?
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue