2017-07-13 09:24:25 +01:00
|
|
|
use clap::{App, AppSettings, ArgMatches, Arg, SubCommand};
|
2017-07-12 14:01:52 +01:00
|
|
|
|
2017-07-12 14:49:53 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
use clap::Result;
|
|
|
|
|
2017-07-13 09:24:25 +01:00
|
|
|
fn get_build_command() -> App<'static, 'static> {
|
|
|
|
return SubCommand::with_name("build")
|
|
|
|
}
|
2017-07-12 14:01:52 +01:00
|
|
|
|
|
|
|
fn build() -> App<'static, 'static> {
|
|
|
|
return App::new(crate_name!())
|
|
|
|
.bin_name("mdp")
|
|
|
|
.about(crate_description!())
|
|
|
|
.version(crate_version!())
|
|
|
|
.setting(AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
.global_setting(AppSettings::VersionlessSubcommands)
|
|
|
|
.global_setting(AppSettings::ColoredHelp)
|
|
|
|
.global_setting(AppSettings::GlobalVersion)
|
|
|
|
.global_setting(AppSettings::StrictUtf8)
|
2017-07-13 09:14:16 +01:00
|
|
|
.arg(Arg::with_name("verbose")
|
|
|
|
.global(true)
|
|
|
|
.short("v")
|
|
|
|
.long("verbose")
|
|
|
|
.help("Show verbose output")
|
|
|
|
.multiple(true)
|
|
|
|
)
|
2017-07-13 09:24:25 +01:00
|
|
|
.subcommand(get_build_command())
|
|
|
|
|
2017-07-12 14:01:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_matches() -> ArgMatches<'static> {
|
|
|
|
return build().get_matches();
|
|
|
|
}
|
2017-07-12 14:49:53 +01:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2017-07-13 09:45:19 +01:00
|
|
|
pub fn get_matches_for(args : Vec<&str>) -> Result<ArgMatches<'static>> {
|
2017-07-12 14:49:53 +01:00
|
|
|
return build().get_matches_from_safe(args);
|
|
|
|
}
|
2017-07-13 09:14:16 +01:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|