pacak / bpaf

Command line parser with applicative interface
336 stars 17 forks source link

bpaf_derive: do the right thing for `collect` #334

Open pacak opened 7 months ago

pacak commented 7 months ago

Currently this code would pass for Vec<String> but not for other collection types. Correct behavior when collect is present would be detect to "peel" the outer level from the type (BTreeSet part) and put it into collect part part while passing inner part (String) to argument.

#[test]                                                                               
fn collect_catch_set() {                     
    let input: NamedField = parse_quote! {                              
        #[bpaf(argument("FILE"), collect, catch)]     
        files: BTreeSet<String>                                                     
    };                                                                          
    let output = quote! { => TokenStream                                        
        ::bpaf::long("files").argument::<String>("FILE").collect::<BTreeSet<_>>().catch()
    };                                                                          
    assert_eq!(input.to_token_stream().to_string(), output.to_string());        
}