2021-11-30 18:30:19 +00:00
|
|
|
use clap::Parser;
|
|
|
|
|
2022-07-19 18:29:31 +00:00
|
|
|
#[derive(Parser)] // requires `derive` feature
|
2024-01-17 14:06:56 +00:00
|
|
|
#[command(version, about, long_about = None)]
|
2021-11-30 18:30:19 +00:00
|
|
|
struct Cli {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(short = 'f')]
|
2021-11-30 18:30:19 +00:00
|
|
|
eff: bool,
|
|
|
|
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(short = 'p', value_name = "PEAR")]
|
2021-11-30 18:30:19 +00:00
|
|
|
pea: Option<String>,
|
|
|
|
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(last = true)]
|
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...
|
|
|
|
}
|