clap/examples/escaped_positional_derive.rs
Ed Page befee6667b docs: Re-work examples
This creates distinct tutorial examples from complex feature examples
(more how-tos).  Both sets are getting builder / derive versions (at
least the critical ones).
2021-11-30 21:33:52 -06:00

25 lines
644 B
Rust

use clap::Parser;
#[derive(Parser)]
#[clap(about, version, author)]
struct Cli {
#[clap(short = 'f')]
eff: bool,
#[clap(short = 'p', value_name = "PEAR")]
pea: Option<String>,
#[clap(last = true)]
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...
}