1 use clap
::{arg, Args as _, Command, FromArgMatches as _, Parser}
;
3 #[derive(Parser, Debug)]
5 #[clap(short, long, action)]
10 let cli
= Command
::new("CLI").arg(arg
!(-b
- -built
).action(clap
::ArgAction
::SetTrue
));
11 // Augment built args with derived args
12 let cli
= DerivedArgs
::augment_args(cli
);
14 let matches
= cli
.get_matches();
16 "Value of built: {:?}",
17 *matches
.get_one
::<bool
>("built").unwrap()
20 "Value of derived via ArgMatches: {:?}",
21 *matches
.get_one
::<bool
>("derived").unwrap()
24 // Since DerivedArgs implements FromArgMatches, we can extract it from the unstructured ArgMatches.
25 // This is the main benefit of using derived arguments.
26 let derived_matches
= DerivedArgs
::from_arg_matches(&matches
)
27 .map_err(|err
| err
.exit())
29 println
!("Value of derived: {:#?}", derived_matches
);