-
Rust Version
Affected Version of clap
Bug SummaryHi all, I'm a first time user of CLAP. I really like it! However, I'm wondering about this The "quick example" using the yaml configuration is ignoring the "multiple" option in the verbosity flag. Passing in any number of What am I missing? Expected Behavior SummaryValue of Actual Behavior SummaryOccurrences of "v" is always equal to zero. Steps to Reproduce the issueCompile, pass any number of
Sample Code or Link to Sample Code#[macro_use]
extern crate clap;
use clap::App;
fn main() {
let yaml = load_yaml!("cli.yaml");
let matches = App::from_yaml(yaml).get_matches();
// Gets a value for config
let config = matches.value_of("config").unwrap_or("default.conf");
println!("Value of config: {}", config);
// Calling .unwrap() is safe here because INPUT is required
println!("Using input file: {}", matches.value_of("INPUT").unwrap());
// Vary the output based on number of verbose flags
println!("{}", matches.occurrences_of("v"));
match matches.occurrences_of("v") {
0 => println!("Aaaaaargghhhh"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
3 | _ => println!("Don't be crazy"),
}
// You can handle information about subcommands
if let Some(matches) = matches.subcommand_matches("test") {
if matches.is_present("debug") {
println!("Printing debug info...");
} else {
println!("Printing normally...");
}
}
} name: "learn_clap"
version: "0.1"
author: Marco
about: It does stuff
args:
- config:
short: c
long: config
value_name: FILE
help: Sets a custom config file
takes_value: true
- INPUT:
help: Sets the input file to use
required: true
index: 1
- verbose:
short: v
multiple: true
help: Sets the level of verbosity
subcommands:
- test:
about: controls testing features
version: "1.3"
author: Some dude
args:
- debug:
short: d
help: print debug information Debug outputCompile clap with cargo features [dependencies]
clap = { version = "2", features = ["debug"] } Debug Output
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
I ran into the same problem today. Using So this is either an actual bug and the short version of arguments should work too, or the example on the main documentation page is faulty. (Refering to clap 2.33.0 and using |
Beta Was this translation helpful? Give feedback.
-
Whoever finds this: you have to use matches.occurrences_of("verbose") but NOT It looks for the YAML key, not the short/long variants: - verbose:
... BUT there is a bug now in the |
Beta Was this translation helpful? Give feedback.
-
Ah, - verbose:
short: v
multiple: true
takes_value: false |
Beta Was this translation helpful? Give feedback.
-
@CreepySkeleton Seems like there is no bug with |
Beta Was this translation helpful? Give feedback.
-
There should be a panic when the arg name is not found when using |
Beta Was this translation helpful? Give feedback.
-
Okay, so we cannot find what is an arg and what is not thus we cannot panic here and the current behaviour is the correct one. |
Beta Was this translation helpful? Give feedback.
Whoever finds this: you have to use
but NOT
matches.occurrences_of("v")
It looks for the YAML key, not the short/long variants:
BUT there is a bug now in the
3.0
version. This works:-v -v -v
, it finds 3 occurrences, but the following doesn't work:-vvv
- it finds 1 occurrence.