tests(Global Args): adds tests for global args

This commit is contained in:
Kevin K 2015-05-22 13:10:34 -04:00
parent 2bcc6137a8
commit c60e9183cc
2 changed files with 9 additions and 9 deletions

View file

@ -140,8 +140,8 @@ USAGE:
claptests subcmd [POSITIONAL] [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
-f, --flag tests flags
-h, --help Prints help information
-v, --version Prints version information
OPTIONS:
@ -161,7 +161,7 @@ positional3 NOT present
option NOT present
positional NOT present
subcmd present
scflag present 1 times
flag present 1 times
scoption present with value: some
An scoption: some
scpositional present with value: value'''
@ -177,7 +177,7 @@ positional3 NOT present
option NOT present
positional NOT present
subcmd present
scflag present 2 times
flag present 2 times
scoption present with value: some
An scoption: some
scpositional present with value: value'''

View file

@ -6,8 +6,7 @@ use clap::{App, Arg, SubCommand};
fn main() {
let m_val_names = ["one", "two"];
let args = "-f --flag... 'tests flags'
-o --option=[opt]... 'tests options'
let args = "-o --option=[opt]... 'tests options'
[positional] 'tests positionals'";
let opt3_vals = ["fast", "slow"];
let pos3_vals = ["vi", "emacs"];
@ -17,6 +16,8 @@ fn main() {
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage(args)
.arg(Arg::from_usage("-f --flag... 'tests flags'")
.global(true))
.args(vec![
Arg::from_usage("[flag2] -F 'tests flags with exclusions'").mutually_excludes("flag").requires("option2"),
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").mutually_excludes("option").requires("positional2"),
@ -32,7 +33,6 @@ fn main() {
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
.arg_from_usage("[scflag] -f --flag... 'tests flags'")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("[scpositional] 'tests positionals'"))
.get_matches();
@ -105,10 +105,10 @@ fn main() {
if matches.is_present("subcmd") {
println!("subcmd present");
if let Some(matches) = matches.subcommand_matches("subcmd") {
if matches.is_present("scflag") {
println!("scflag present {} times", matches.occurrences_of("scflag"));
if matches.is_present("flag") {
println!("flag present {} times", matches.occurrences_of("flag"));
} else {
println!("scflag NOT present");
println!("flag NOT present");
}
if matches.is_present("scoption") {