mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 16:47:21 +00:00
03cb509d6c
This is to make room for a reasonable looking cargo plugin example. I got lazy and didn't update the tutorials.
26 lines
902 B
Rust
26 lines
902 B
Rust
// Note: this requires the `cargo` feature
|
|
|
|
use clap::{app_from_crate, arg};
|
|
|
|
fn main() {
|
|
let matches = app_from_crate!()
|
|
.arg(arg!(eff: -f))
|
|
.arg(arg!(pea: -p <PEAR>).required(false))
|
|
.arg(
|
|
arg!(slop: [SLOP]).multiple_occurrences(true).last(true), // Indicates that `slop` is only accessible after `--`.
|
|
)
|
|
.get_matches();
|
|
|
|
// 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")
|
|
println!(
|
|
"'slops' values: {:?}",
|
|
matches
|
|
.values_of("slop")
|
|
.map(|vals| vals.collect::<Vec<_>>())
|
|
.unwrap_or_default()
|
|
); // 'slops' values: Some(["sloppy", "slop", "slop"])
|
|
|
|
// Continued program logic goes here...
|
|
}
|