-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clap_app!): Support
--("some-arg-name")
syntax for defining lo…
…ng arg names Used for arg names that aren't idents. Ref #321
- Loading branch information
Arnavion
committed
Dec 13, 2016
1 parent
9895b67
commit f41ec96
Showing
3 changed files
with
42 additions
and
0 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
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 |
---|---|---|
|
@@ -73,3 +73,41 @@ fn quoted_app_name() { | |
let help_text = String::from_utf8(help_text).expect("Help text is not valid utf-8"); | ||
assert!(help_text.starts_with("app name with spaces-and-hyphens 0.1\n")); | ||
} | ||
|
||
#[test] | ||
fn quoted_arg_long_name() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@arg opt: -o --option +takes_value ... "tests options") | ||
(@arg positional: index(1) "tests positionals") | ||
(@arg flag: -f --flag ... +global "tests flags") | ||
(@arg flag2: -F conflicts_with[flag] requires[option2] | ||
"tests flags with exclusions") | ||
(@arg option2: --("long-option-2") conflicts_with[option] requires[positional2] | ||
"tests long options with exclusions") | ||
(@arg positional2: index(2) "tests positionals with exclusions") | ||
(@arg option3: -O --Option +takes_value possible_value[fast slow] | ||
"tests options with specific value sets") | ||
(@arg positional3: index(3) ... possible_value[vi emacs] | ||
"tests positionals with specific values") | ||
(@arg multvals: --multvals +takes_value value_name[one two] | ||
"Tests mutliple values, not mult occs") | ||
(@arg multvalsmo: --multvalsmo ... +takes_value value_name[one two] | ||
"Tests mutliple values, not mult occs") | ||
(@arg minvals: --minvals2 min_values(1) ... +takes_value "Tests 2 min vals") | ||
(@arg maxvals: --maxvals3 ... +takes_value max_values(3) "Tests 3 max vals") | ||
(@subcommand subcmd => | ||
(about: "tests subcommands") | ||
(version: "0.1") | ||
(author: "Kevin K. <[email protected]>") | ||
(@arg scoption: -o --option ... +takes_value "tests options") | ||
(@arg scpositional: index(1) "tests positionals")) | ||
); | ||
|
||
assert_eq!(app.p.long_list[2], "long-option-2"); | ||
|
||
let matches = app.get_matches_from_safe(vec!["bin_name", "value1", "value2", "--long-option-2"]).expect("Expected to successfully match the given args."); | ||
assert!(matches.is_present("option2")); | ||
} |