-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
819 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,21 +281,21 @@ The next example shows a far less verbose method, but sacrifices some of the adv | |
// | ||
// This example demonstrates clap's "usage strings" method of creating arguments | ||
// which is less verbose | ||
use clap::{App, Arg}; | ||
use clap::{App, arg}; | ||
fn main() { | ||
let matches = App::new("myapp") | ||
.version("1.0") | ||
.author("Kevin K. <[email protected]>") | ||
.about("Does awesome things") | ||
.arg(Arg::from_usage("-c, --config=[FILE] 'Sets a custom config file'")) | ||
.arg(Arg::from_usage("<INPUT> 'Sets the input file to use'")) | ||
.arg(Arg::from_usage("-v... 'Sets the level of verbosity'")) | ||
.arg(arg!(-c --config <FILE> "Sets a custom config file").required(false)) | ||
.arg(arg!(<INPUT> "Sets the input file to use")) | ||
.arg(arg!(-v --verbose ... "Sets the level of verbosity")) | ||
.subcommand(App::new("test") | ||
.about("controls testing features") | ||
.version("1.3") | ||
.author("Someone E. <[email protected]>") | ||
.arg(Arg::from_usage("-d, --debug 'Print debug information'"))) | ||
.arg(arg!(-d --debug "Print debug information"))) | ||
.get_matches(); | ||
// Same as previous example... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use clap::{App, Arg}; | ||
use clap::{arg, App, Arg}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
macro_rules! create_app { | ||
|
@@ -7,9 +7,9 @@ macro_rules! create_app { | |
.version("0.1") | ||
.about("tests clap library") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(Arg::from_usage("-f --flag 'tests flags'")) | ||
.arg(Arg::from_usage("-o --option=[opt] 'tests options'")) | ||
.arg(Arg::from_usage("[positional] 'tests positional'")) | ||
.arg(arg!(-f --flag "tests flags")) | ||
.arg(arg!(-o --option <opt> "tests options").required(false)) | ||
.arg(arg!([positional] "tests positional")) | ||
}}; | ||
} | ||
|
||
|
@@ -19,29 +19,29 @@ pub fn build_simple(c: &mut Criterion) { | |
|
||
pub fn build_with_flag(c: &mut Criterion) { | ||
c.bench_function("build_with_flag", |b| { | ||
b.iter(|| App::new("claptests").arg(Arg::from_usage("-s, --some 'something'"))) | ||
b.iter(|| App::new("claptests").arg(arg!(-s --some "something"))) | ||
}); | ||
} | ||
|
||
pub fn build_with_flag_ref(c: &mut Criterion) { | ||
c.bench_function("build_with_flag_ref", |b| { | ||
b.iter(|| { | ||
let arg = Arg::from_usage("-s, --some 'something'"); | ||
let arg = arg!(-s --some "something"); | ||
App::new("claptests").arg(&arg) | ||
}) | ||
}); | ||
} | ||
|
||
pub fn build_with_opt(c: &mut Criterion) { | ||
c.bench_function("build_with_opt", |b| { | ||
b.iter(|| App::new("claptests").arg(Arg::from_usage("-s, --some <FILE> 'something'"))) | ||
b.iter(|| App::new("claptests").arg(arg!(-s --some <FILE> "something"))) | ||
}); | ||
} | ||
|
||
pub fn build_with_opt_ref(c: &mut Criterion) { | ||
c.bench_function("build_with_opt_ref", |b| { | ||
b.iter(|| { | ||
let arg = Arg::from_usage("-s, --some <FILE> 'something'"); | ||
let arg = arg!(-s --some <FILE> "something"); | ||
App::new("claptests").arg(&arg) | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
use clap::{App, AppSettings, Arg, ArgSettings}; | ||
use clap::{arg, App, AppSettings, Arg, ArgSettings}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
static OPT3_VALS: [&str; 2] = ["fast", "slow"]; | ||
static POS3_VALS: [&str; 2] = ["vi", "emacs"]; | ||
|
||
macro_rules! create_app { | ||
() => {{ | ||
App::new("claptests") | ||
.version("0.1") | ||
.about("tests clap library") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(arg!(-o --option <opt> ... "tests options").required(false)) | ||
.arg(arg!([positional] "tests positionals")) | ||
.arg(arg!(-f --flag ... "tests flags").global(true)) | ||
.args(&[ | ||
arg!(flag2: -F "tests flags with exclusions") | ||
.conflicts_with("flag") | ||
.requires("option2"), | ||
arg!(option2: --"long-option-2" <option2> "tests long options with exclusions") | ||
.required(false) | ||
.conflicts_with("option") | ||
.requires("positional2"), | ||
arg!([positional2] "tests positionals with exclusions"), | ||
arg!(-O --Option <option3> "tests options with specific value sets") | ||
.required(false) | ||
.possible_values(OPT3_VALS), | ||
arg!([positional3] ... "tests positionals with specific values") | ||
.possible_values(POS3_VALS), | ||
arg!(--multvals "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]), | ||
arg!( | ||
--multvalsmo "Tests multiple values, not mult occs" | ||
).multiple_values(true).required(false).value_names(&["one", "two"]), | ||
arg!(--minvals2 <minvals> ... "Tests 2 min vals").min_values(2).multiple_values(true).required(false), | ||
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").max_values(3).multiple_values(true).required(false), | ||
]) | ||
.subcommand( | ||
App::new("subcmd") | ||
.about("tests subcommands") | ||
.version("0.1") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(arg!(-o --option <scoption> ... "tests options").required(false)) | ||
.arg(arg!([scpositional] "tests positionals")) | ||
) | ||
}}; | ||
} | ||
|
||
macro_rules! create_app_from_usage { | ||
() => {{ | ||
App::new("claptests") | ||
.version("0.1") | ||
|
@@ -46,7 +87,7 @@ macro_rules! create_app { | |
} | ||
|
||
pub fn build_from_usage(c: &mut Criterion) { | ||
c.bench_function("build_from_usage", |b| b.iter(|| create_app!())); | ||
c.bench_function("build_from_usage", |b| b.iter(|| create_app_from_usage!())); | ||
} | ||
|
||
pub fn build_from_builder(c: &mut Criterion) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use clap::App; | ||
use clap::{Arg, ArgSettings}; | ||
use clap::{arg, Arg, ArgSettings}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::io::Cursor; | ||
|
||
|
@@ -15,15 +15,18 @@ fn app_example1<'c>() -> App<'c> { | |
.version("1.0") | ||
.author("Kevin K. <[email protected]>") | ||
.about("Does awesome things") | ||
.arg(Arg::from_usage( | ||
"-c, --config=[FILE] 'Sets a custom config file'", | ||
)) | ||
.arg(Arg::from_usage("<output> 'Sets an optional output file'")) | ||
.arg(Arg::from_usage("-d... 'Turn debugging information on'")) | ||
.arg( | ||
arg!( | ||
-c --config <FILE> "Sets a custom config file" | ||
) | ||
.required(false), | ||
) | ||
.arg(arg!(<output> "Sets an optional output file")) | ||
.arg(arg!(d: -d ... "Turn debugging information on")) | ||
.subcommand( | ||
App::new("test") | ||
.about("does testing things") | ||
.arg(Arg::from_usage("-l, --list 'lists test values'")), | ||
.arg(arg!(-l --list "lists test values")), | ||
) | ||
} | ||
|
||
|
@@ -51,11 +54,14 @@ fn app_example3<'c>() -> App<'c> { | |
.help("the input file to use") | ||
.setting(ArgSettings::Required), | ||
]) | ||
.arg(Arg::from_usage("--license 'display the license file'")) | ||
.arg(Arg::from_usage("[output] 'Supply an output file to use'")) | ||
.arg(Arg::from_usage( | ||
"-i, --int=[IFACE] 'Set an interface to use'", | ||
)) | ||
.arg(arg!(--license "display the license file")) | ||
.arg(arg!([output] "Supply an output file to use")) | ||
.arg( | ||
arg!( | ||
-i --int <IFACE> "Set an interface to use" | ||
) | ||
.required(false), | ||
) | ||
} | ||
|
||
fn app_example4<'c>() -> App<'c> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use clap::{App, Arg}; | ||
use clap::{arg, App}; | ||
|
||
fn main() { | ||
// This example shows how to create an application with several arguments using usage strings, which can be | ||
|
@@ -33,17 +33,20 @@ fn main() { | |
.version("1.0") | ||
.author("Kevin K. <[email protected]>") | ||
.about("Does awesome things") | ||
.arg(Arg::from_usage( | ||
"-c, --config=[FILE] 'Sets a custom config file'", | ||
)) | ||
.arg(Arg::from_usage("[output] 'Sets an optional output file'")) | ||
.arg(Arg::from_usage( | ||
"-d..., --debug... 'Turn debugging information on'", | ||
.arg( | ||
arg!( | ||
-c --config <FILE> "Sets a custom config file" | ||
) | ||
.required(false), | ||
) | ||
.arg(arg!([output] "Sets an optional output file")) | ||
.arg(arg!( | ||
-d --debug ... "Turn debugging information on" | ||
)) | ||
.subcommand( | ||
App::new("test") | ||
.about("does testing things") | ||
.arg(Arg::from_usage("-l, --list 'lists test values'")), | ||
.arg(arg!(-l --list "lists test values")), | ||
) | ||
.get_matches(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.