forked from clap-rs/clap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request clap-rs#3746 from epage/fixes
fix(parser): Increase compatibility between old/new approach
- Loading branch information
Showing
33 changed files
with
338 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
// Note: this requires the `cargo` feature | ||
|
||
use clap::{arg, command}; | ||
use clap::{arg, command, value_parser}; | ||
|
||
fn main() { | ||
let matches = command!() | ||
.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 `--`. | ||
arg!(pea: -p <PEAR>) | ||
.required(false) | ||
.value_parser(value_parser!(String)), | ||
) | ||
.arg( | ||
// Indicates that `slop` is only accessible after `--`. | ||
arg!(slop: [SLOP]) | ||
.multiple_occurrences(true) | ||
.last(true) | ||
.value_parser(value_parser!(String)), | ||
) | ||
.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") | ||
|
||
// -f used: true | ||
println!("-f used: {:?}", matches.is_present("eff")); | ||
// -p's value: Some("bob") | ||
println!( | ||
"-p's value: {:?}", | ||
matches | ||
.get_one::<String>("pea") | ||
.expect("matches definition") | ||
); | ||
// 'slops' values: Some(["sloppy", "slop", "slop"]) | ||
println!( | ||
"'slops' values: {:?}", | ||
matches | ||
.values_of("slop") | ||
.get_many::<String>("slop") | ||
.expect("matches definition") | ||
.map(|vals| vals.collect::<Vec<_>>()) | ||
.unwrap_or_default() | ||
); // 'slops' values: Some(["sloppy", "slop", "slop"]) | ||
); | ||
|
||
// Continued program logic goes here... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.