1 use clap
::error
::Error
;
2 use clap
::{Arg, ArgAction, ArgMatches, Args, Command, FromArgMatches, Parser}
;
11 impl FromArgMatches
for CliArgs
{
12 fn from_arg_matches(matches
: &ArgMatches
) -> Result
<Self, Error
> {
13 let mut matches
= matches
.clone();
14 Self::from_arg_matches_mut(&mut matches
)
16 fn from_arg_matches_mut(matches
: &mut ArgMatches
) -> Result
<Self, Error
> {
18 foo
: *matches
.get_one
::<bool
>("foo").expect("defaulted by clap"),
19 bar
: *matches
.get_one
::<bool
>("bar").expect("defaulted by clap"),
20 quuz
: matches
.remove_one
::<String
>("quuz"),
23 fn update_from_arg_matches(&mut self, matches
: &ArgMatches
) -> Result
<(), Error
> {
24 let mut matches
= matches
.clone();
25 self.update_from_arg_matches_mut(&mut matches
)
27 fn update_from_arg_matches_mut(&mut self, matches
: &mut ArgMatches
) -> Result
<(), Error
> {
28 self.foo
|= *matches
.get_one
::<bool
>("foo").expect("defaulted by clap");
29 self.bar
|= *matches
.get_one
::<bool
>("bar").expect("defaulted by clap");
30 if let Some(quuz
) = matches
.remove_one
::<String
>("quuz") {
31 self.quuz
= Some(quuz
);
37 impl Args
for CliArgs
{
38 fn augment_args(cmd
: Command
<'_
>) -> Command
<'_
> {
43 .action(ArgAction
::SetTrue
),
49 .action(ArgAction
::SetTrue
),
51 .arg(Arg
::new("quuz").short('q'
).long("quuz").takes_value(true))
53 fn augment_args_for_update(cmd
: Command
<'_
>) -> Command
<'_
> {
58 .action(ArgAction
::SetTrue
),
64 .action(ArgAction
::SetTrue
),
66 .arg(Arg
::new("quuz").short('q'
).long("quuz").takes_value(true))
70 #[derive(Parser, Debug)]
72 #[clap(short, long, action)]
79 let args
= Cli
::parse();
80 println
!("{:#?}", args
);