Add verbose flag and complex getter
This commit is contained in:
parent
c8cf6f0c51
commit
65a6c1b368
2 changed files with 14 additions and 2 deletions
14
src/args.rs
14
src/args.rs
|
@ -1,4 +1,4 @@
|
||||||
use clap::{App, AppSettings, ArgMatches};
|
use clap::{App, AppSettings, ArgMatches, Arg};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use clap::Result;
|
use clap::Result;
|
||||||
|
@ -14,6 +14,13 @@ fn build() -> App<'static, 'static> {
|
||||||
.global_setting(AppSettings::ColoredHelp)
|
.global_setting(AppSettings::ColoredHelp)
|
||||||
.global_setting(AppSettings::GlobalVersion)
|
.global_setting(AppSettings::GlobalVersion)
|
||||||
.global_setting(AppSettings::StrictUtf8)
|
.global_setting(AppSettings::StrictUtf8)
|
||||||
|
.arg(Arg::with_name("verbose")
|
||||||
|
.global(true)
|
||||||
|
.short("v")
|
||||||
|
.long("verbose")
|
||||||
|
.help("Show verbose output")
|
||||||
|
.multiple(true)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,3 +32,8 @@ pub fn get_matches() -> ArgMatches<'static> {
|
||||||
pub fn get_matches_for(args : Vec<String>) -> Result<ArgMatches<'static>> {
|
pub fn get_matches_for(args : Vec<String>) -> Result<ArgMatches<'static>> {
|
||||||
return build().get_matches_from_safe(args);
|
return build().get_matches_from_safe(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_verbose(m : ArgMatches) -> u64 {
|
||||||
|
let sub = m.subcommand_matches(&m.subcommand_name().unwrap()).unwrap();
|
||||||
|
m.occurrences_of("verbose") + sub.occurrences_of("verbose")
|
||||||
|
}
|
||||||
|
|
|
@ -7,5 +7,5 @@ mod args;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = args::get_matches();
|
args::get_matches();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue