2021-11-30 18:30:19 +00:00
|
|
|
use clap::Parser;
|
|
|
|
|
2022-07-19 18:29:31 +00:00
|
|
|
#[derive(Parser)] // requires `derive` feature
|
2022-01-11 00:47:20 +00:00
|
|
|
#[clap(author, version, about, long_about = None)]
|
2021-11-30 18:30:19 +00:00
|
|
|
struct Cli {
|
2022-06-01 15:31:23 +00:00
|
|
|
#[clap(short = 'f', action)]
|
2021-11-30 18:30:19 +00:00
|
|
|
eff: bool,
|
|
|
|
|
2022-05-21 00:52:04 +00:00
|
|
|
#[clap(short = 'p', value_name = "PEAR", value_parser)]
|
2021-11-30 18:30:19 +00:00
|
|
|
pea: Option<String>,
|
|
|
|
|
2022-05-21 00:52:04 +00:00
|
|
|
#[clap(last = true, value_parser)]
|
2021-11-30 18:30:19 +00:00
|
|
|
slop: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = Cli::parse();
|
|
|
|
|
|
|
|
// This is what will happen with `myprog -f -p=bob -- sloppy slop slop`...
|
|
|
|
println!("-f used: {:?}", args.eff); // -f used: true
|
|
|
|
println!("-p's value: {:?}", args.pea); // -p's value: Some("bob")
|
|
|
|
println!("'slops' values: {:?}", args.slop); // 'slops' values: Some(["sloppy", "slop", "slop"])
|
|
|
|
|
|
|
|
// Continued program logic goes here...
|
|
|
|
}
|