2021-11-30 18:30:19 +00:00
|
|
|
use clap::{app_from_crate, arg};
|
2017-05-31 19:41:54 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-11-30 18:30:19 +00:00
|
|
|
let matches = app_from_crate!()
|
|
|
|
.arg(arg!(eff: -f))
|
|
|
|
.arg(arg!(pea: -p <PEAR>).required(false))
|
2021-06-16 05:28:25 +00:00
|
|
|
.arg(
|
2021-11-30 18:30:19 +00:00
|
|
|
arg!(slop: [SLOP]).multiple_occurrences(true).last(true), // Indicates that `slop` is only accessible after `--`.
|
2021-06-16 05:28:25 +00:00
|
|
|
)
|
2017-05-31 19:41:54 +00:00
|
|
|
.get_matches();
|
|
|
|
|
2021-08-03 11:41:54 +00:00
|
|
|
// This is what will happen with `myprog -f -p=bob -- sloppy slop slop`...
|
|
|
|
println!("-f used: {:?}", matches.is_present("eff")); // -f used: true
|
|
|
|
println!("-p's value: {:?}", matches.value_of("pea")); // -p's value: Some("bob")
|
2018-01-25 04:05:05 +00:00
|
|
|
println!(
|
|
|
|
"'slops' values: {:?}",
|
|
|
|
matches
|
|
|
|
.values_of("slop")
|
|
|
|
.map(|vals| vals.collect::<Vec<_>>())
|
2021-11-30 18:30:19 +00:00
|
|
|
.unwrap_or_default()
|
2021-08-03 11:41:54 +00:00
|
|
|
); // 'slops' values: Some(["sloppy", "slop", "slop"])
|
2017-05-31 19:41:54 +00:00
|
|
|
|
|
|
|
// Continued program logic goes here...
|
|
|
|
}
|