|
1 | | -use clap::{App, AppSettings, Arg, ArgSettings}; |
| 1 | +use clap::{arg, App, AppSettings, Arg, ArgSettings}; |
2 | 2 | use criterion::{criterion_group, criterion_main, Criterion}; |
3 | 3 |
|
4 | 4 | static OPT3_VALS: [&str; 2] = ["fast", "slow"]; |
5 | 5 | static POS3_VALS: [&str; 2] = ["vi", "emacs"]; |
6 | 6 |
|
7 | 7 | macro_rules! create_app { |
| 8 | + () => {{ |
| 9 | + App::new("claptests") |
| 10 | + .version("0.1") |
| 11 | + .about("tests clap library") |
| 12 | + .author ("Kevin K. <[email protected]>") |
| 13 | + .arg(arg!(-o --option <opt> ... "tests options").required(false)) |
| 14 | + .arg(arg!([positional] "tests positionals")) |
| 15 | + .arg(arg!(-f --flag ... "tests flags").global(true)) |
| 16 | + .args(&[ |
| 17 | + arg!(flag2: -F "tests flags with exclusions") |
| 18 | + .conflicts_with("flag") |
| 19 | + .requires("option2"), |
| 20 | + arg!(option2: --"long-option-2" <option2> "tests long options with exclusions") |
| 21 | + .required(false) |
| 22 | + .conflicts_with("option") |
| 23 | + .requires("positional2"), |
| 24 | + arg!([positional2] "tests positionals with exclusions"), |
| 25 | + arg!(-O --Option <option3> "tests options with specific value sets") |
| 26 | + .required(false) |
| 27 | + .possible_values(OPT3_VALS), |
| 28 | + arg!([positional3] ... "tests positionals with specific values") |
| 29 | + .possible_values(POS3_VALS), |
| 30 | + arg!(--multvals "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]), |
| 31 | + arg!( |
| 32 | + --multvalsmo "Tests multiple values, not mult occs" |
| 33 | + ).multiple_values(true).required(false).value_names(&["one", "two"]), |
| 34 | + arg!(--minvals2 <minvals> ... "Tests 2 min vals").min_values(2).multiple_values(true).required(false), |
| 35 | + arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").max_values(3).multiple_values(true).required(false), |
| 36 | + ]) |
| 37 | + .subcommand( |
| 38 | + App::new("subcmd") |
| 39 | + .about("tests subcommands") |
| 40 | + .version("0.1") |
| 41 | + .author ("Kevin K. <[email protected]>") |
| 42 | + .arg(arg!(-o --option <scoption> ... "tests options").required(false)) |
| 43 | + .arg(arg!([scpositional] "tests positionals")) |
| 44 | + ) |
| 45 | + }}; |
| 46 | +} |
| 47 | + |
| 48 | +macro_rules! create_app_from_usage { |
8 | 49 | () => {{ |
9 | 50 | App::new("claptests") |
10 | 51 | .version("0.1") |
@@ -46,7 +87,7 @@ macro_rules! create_app { |
46 | 87 | } |
47 | 88 |
|
48 | 89 | pub fn build_from_usage(c: &mut Criterion) { |
49 | | - c.bench_function("build_from_usage", |b| b.iter(|| create_app!())); |
| 90 | + c.bench_function("build_from_usage", |b| b.iter(|| create_app_from_usage!())); |
50 | 91 | } |
51 | 92 |
|
52 | 93 | pub fn build_from_builder(c: &mut Criterion) { |
|
0 commit comments