forked from clap-rs/clap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make
arg!(--flag <value>)
optional by default
This was ported over from the usage parser which modeled after docopt. We just never got around to implementing the rest of the syntax. However, when considering this as a standalone feature, an `arg!(--flag <value>)`, outside of other context, should be optional. This is how the help would display it. Fixes clap-rs#4206
- Loading branch information
Showing
31 changed files
with
177 additions
and
301 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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ macro_rules! create_app { | |
.about("tests clap library") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(arg!(-f --flag "tests flags")) | ||
.arg(arg!(-o --option <opt> "tests options").required(false)) | ||
.arg(arg!(-o --option <opt> "tests options")) | ||
.arg(arg!([positional] "tests positional")) | ||
}}; | ||
} | ||
|
@@ -34,14 +34,14 @@ pub fn build_with_flag_ref(c: &mut Criterion) { | |
|
||
pub fn build_with_opt(c: &mut Criterion) { | ||
c.bench_function("build_with_opt", |b| { | ||
b.iter(|| Command::new("claptests").arg(arg!(-s --some <FILE> "something"))) | ||
b.iter(|| Command::new("claptests").arg(arg!(-s --some <FILE> "something").required(true))) | ||
}); | ||
} | ||
|
||
pub fn build_with_opt_ref(c: &mut Criterion) { | ||
c.bench_function("build_with_opt_ref", |b| { | ||
b.iter(|| { | ||
let arg = arg!(-s --some <FILE> "something"); | ||
let arg = arg!(-s --some <FILE> "something").required(true); | ||
Command::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 |
---|---|---|
|
@@ -10,36 +10,34 @@ macro_rules! create_app { | |
.version("0.1") | ||
.about("tests clap library") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(arg!(-o --option <opt> ... "tests options").required(false)) | ||
.arg(arg!(-o --option <opt> ... "tests options")) | ||
.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) | ||
.value_parser(OPT3_VALS), | ||
arg!([positional3] ... "tests positionals with specific values") | ||
.value_parser(POS3_VALS), | ||
arg!(--multvals <s> "Tests multiple values not mult occs").required(false).value_names(["one", "two"]), | ||
arg!(--multvals <s> "Tests multiple values not mult occs").value_names(["one", "two"]), | ||
arg!( | ||
--multvalsmo <s> "Tests multiple values, not mult occs" | ||
).required(false).value_names(["one", "two"]), | ||
arg!(--minvals2 <minvals> ... "Tests 2 min vals").num_args(2..).required(false), | ||
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").num_args(1..=3).required(false), | ||
arg!(--minvals2 <minvals> ... "Tests 2 min vals").num_args(2..), | ||
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").num_args(1..=3), | ||
]) | ||
.subcommand( | ||
Command::new("subcmd") | ||
.about("tests subcommands") | ||
.version("0.1") | ||
.author("Kevin K. <[email protected]>") | ||
.arg(arg!(-o --option <scoption> ... "tests options").required(false)) | ||
.arg(arg!(-o --option <scoption> ... "tests options")) | ||
.arg(arg!([scpositional] "tests positionals")) | ||
) | ||
}}; | ||
|
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
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 |
---|---|---|
|
@@ -5,8 +5,8 @@ fn main() { | |
.version("1.0") | ||
.author("Kevin K. <[email protected]>") | ||
.about("Does awesome things") | ||
.arg(arg!(--two <VALUE>)) | ||
.arg(arg!(--one <VALUE>)) | ||
.arg(arg!(--two <VALUE>).required(true)) | ||
.arg(arg!(--one <VALUE>).required(true)) | ||
.get_matches(); | ||
|
||
println!( | ||
|
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
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.