mirror of
https://github.com/clap-rs/clap
synced 2024-11-15 00:57:15 +00:00
docs: update example, mentioning the pseudo-flag
pattern
This commit is contained in:
parent
a4a4d4c307
commit
38649cc0b5
1 changed files with 14 additions and 0 deletions
|
@ -29,6 +29,15 @@ fn main() {
|
|||
// also has a conflicts_with_all(Vec<&str>)
|
||||
// and an exclusive(true)
|
||||
)
|
||||
.arg(
|
||||
// Sometimes we might want to accept one of the following: `--pseudo-flag`, `--pseudo-flag=true`, `--pseudo-flag=false.`
|
||||
// The following is the `pseudo-flag` pattern stated in https://github.com/clap-rs/clap/issues/1649#issuecomment-661274943
|
||||
Arg::new("pseudo-flag") // Create a "pesudo-flag" with optional value
|
||||
.possible_values(&["true", "false"]) // Limit that value to `true` of `false`
|
||||
.long("pseudo-flag")
|
||||
.min_values(0)
|
||||
.max_values(1),
|
||||
)
|
||||
.arg("-c, --config=[FILE] 'sets a custom config file'")
|
||||
.arg("<output> 'sets an output file'")
|
||||
.get_matches();
|
||||
|
@ -38,6 +47,11 @@ fn main() {
|
|||
println!("Awesomeness is turned on");
|
||||
}
|
||||
|
||||
// Same thing with `pseudo-flag`
|
||||
if app.value_of("pseudo-flag") != Some("false") {
|
||||
println!("Pseudo-flag is turned on");
|
||||
}
|
||||
|
||||
// If we set the multiple option of a flag we can check how many times the user specified
|
||||
//
|
||||
// Note: if we did not specify the multiple option, and the user used "awesome" we would get
|
||||
|
|
Loading…
Reference in a new issue