From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../rust/clap/examples/escaped-positional.rs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 third_party/rust/clap/examples/escaped-positional.rs (limited to 'third_party/rust/clap/examples/escaped-positional.rs') diff --git a/third_party/rust/clap/examples/escaped-positional.rs b/third_party/rust/clap/examples/escaped-positional.rs new file mode 100644 index 0000000000..f6d61bd965 --- /dev/null +++ b/third_party/rust/clap/examples/escaped-positional.rs @@ -0,0 +1,26 @@ +// Note: this requires the `cargo` feature + +use clap::{arg, command}; + +fn main() { + let matches = command!() + .arg(arg!(eff: -f)) + .arg(arg!(pea: -p ).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::>()) + .unwrap_or_default() + ); // 'slops' values: Some(["sloppy", "slop", "slop"]) + + // Continued program logic goes here... +} -- cgit v1.2.3