1 use clap::{arg, command, value_parser, ArgAction};
2 
main()3 fn main() {
4     let matches = command!() // requires `cargo` feature
5         .arg(arg!(eff: -f).action(ArgAction::SetTrue))
6         .arg(
7             arg!(pea: -p <PEAR>)
8                 .required(false)
9                 .value_parser(value_parser!(String)),
10         )
11         .arg(
12             // Indicates that `slop` is only accessible after `--`.
13             arg!(slop: [SLOP])
14                 .multiple_values(true)
15                 .last(true)
16                 .value_parser(value_parser!(String)),
17         )
18         .get_matches();
19 
20     // This is what will happen with `myprog -f -p=bob -- sloppy slop slop`...
21 
22     // -f used: true
23     println!("-f used: {:?}", matches.get_flag("eff"));
24     // -p's value: Some("bob")
25     println!("-p's value: {:?}", matches.get_one::<String>("pea"));
26     // 'slops' values: Some(["sloppy", "slop", "slop"])
27     println!(
28         "'slops' values: {:?}",
29         matches
30             .get_many::<String>("slop")
31             .map(|vals| vals.collect::<Vec<_>>())
32             .unwrap_or_default()
33     );
34 
35     // Continued program logic goes here...
36 }
37