Skip to content

Commit

Permalink
Merge pull request #132 from kbknapp/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
kbknapp committed May 23, 2015
2 parents ad4dd9d + 743eefe commit ace4f1a
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 159 deletions.
1 change: 1 addition & 0 deletions .clog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ from-latest-tag = true
Performance = ["perf"]
Improvements = ["impr", "im", "imp"]
Documentation = ["docs"]
Deprecations = ["depr"]
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Below are a few of the features which `clap` supports, full descriptions and usa
* **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details and performs an ascii case insensitive parse from a `string`->`enum`.
* **Suggestions**: Suggests corrections when the user enter's a typo. For example, if you defined a `--myoption <value>` argument, and the user mistakenly typed `--moyption value` (notice `y` and `o` switched), they would receive a `Did you mean '--myoption' ?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
* **Colorized (Red) Errors**: Error message are printed in red text (this feature can optionally be disabled, see 'Optional Dependencies / Features').
* **Global Arguments**: Arguments can optionally be defined once, and be available to all child subcommands.

## Quick Example

Expand Down Expand Up @@ -369,7 +370,10 @@ Although I do my best to keep breaking changes to a minimum, being that this a s

Old method names will be left around for some time.

* As of 0.10.0
- `SubCommand::new()` -> `SubCommand::with_name()`
- `App::error_on_no_subcommand()` -> `App::subcommand_required()`
* As of 0.6.8
- `Arg::new()` -> `Arg::with_name()`
- `Arg::mutually_excludes()` -> `Arg::conflicts_with()`
- `Arg::mutually_excludes_all()` -> `Arg::conflicts_with_all()`
- `Arg::new()` -> `Arg::with_name()`
- `Arg::mutually_excludes()` -> `Arg::conflicts_with()`
- `Arg::mutually_excludes_all()` -> `Arg::conflicts_with_all()`
31 changes: 16 additions & 15 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
--multvalsmo <one> <two> Tests mutliple values, not mult occs
-o, --option <opt>... tests options
--long-option-2 <option2> tests long options with exclusions
-O, --Option <option3> tests options with specific value sets [values: fast slow]
-O, --Option <option3> tests options with specific value sets [values: fast, slow]
POSITIONAL ARGUMENTS:
positional tests positionals
positional2 tests positionals with exclusions
positional3... tests positionals with specific values [values: emacs vi]
positional3... tests positionals with specific values [values: emacs, vi]
SUBCOMMANDS:
help Prints this message
subcmd tests subcommands'''

_sc_dym_usage = '''The subcommand 'subcm' isn't valid
_sc_dym_usage = '''error: The subcommand 'subcm' isn't valid
Did you mean 'subcmd' ?
If you received this message in error, try re-running with 'claptests -- subcm'
Expand All @@ -48,38 +48,39 @@
For more information try --help'''

_arg_dym_usage = '''The argument --optio isn't valid
_arg_dym_usage = '''error: The argument '--optio' isn't valid
Did you mean --option ?
USAGE:
claptests --option <opt>...
For more information try --help'''

_pv_dym_usage = '''"slo" isn't a valid value for '--Option <option3>'
_pv_dym_usage = '''error: 'slo' isn't a valid value for '--Option <option3>'
[valid values: fast slow]
Did you mean 'slow' ?
USAGE:
claptests --Option <option3>
For more information try --help'''

_excluded = '''The argument '--flag' cannot be used with '-F'
_excluded = '''error: The argument '--flag' cannot be used with '-F'
USAGE:
\tclaptests [positional2] -F --long-option-2 <option2>
For more information try --help'''

_excluded_l = '''The argument -f cannot be used '-F'
_excluded_l = '''error: The argument '-f' cannot be used '-F'
USAGE:
claptests [positional2] -F --long-option-2 <option2>
For more information try --help'''

_required = '''The following required arguments were not supplied:
_required = '''error: The following required arguments were not supplied:
\t'[positional2]'
\t'--long-option-2 <option2>'
Expand Down Expand Up @@ -140,8 +141,8 @@
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:
Expand All @@ -161,7 +162,7 @@
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'''
Expand All @@ -177,12 +178,12 @@
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'''

_min_vals_few = '''The argument '--minvals2 <minvals>...' requires at least 2 values, but 1 was provided
_min_vals_few = '''error: The argument '--minvals2 <minvals>...' requires at least 2 values, but 1 was provided
USAGE:
\tclaptests --minvals2 <minvals>...
Expand Down Expand Up @@ -213,21 +214,21 @@
positional present with value: too
subcmd NOT present'''

_mult_vals_more = '''The argument --multvals was supplied more than once, but does not support multiple values
_mult_vals_more = '''error: The argument '--multvals' was supplied more than once, but does not support multiple values
USAGE:
\tclaptests --multvals <one> <two>
For more information try --help'''

_mult_vals_few = '''The argument '--multvals <one> <two>' requires a value but none was supplied
_mult_vals_few = '''error: The argument '--multvals <one> <two>' requires a value but none was supplied
USAGE:
\tclaptests --multvals <one> <two>
For more information try --help'''

_mult_vals_2m1 = '''The argument '--multvalsmo <one> <two>' requires 2 values, but 1 was provided
_mult_vals_2m1 = '''error: The argument '--multvalsmo <one> <two>' requires 2 values, but 1 was provided
USAGE:
claptests --multvalsmo <one> <two>
Expand Down
12 changes: 6 additions & 6 deletions clap-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -17,6 +16,8 @@ fn main() {
.about("tests clap library")
.author("Kevin K. <[email protected]>")
.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"),
Expand All @@ -32,7 +33,6 @@ fn main() {
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <[email protected]>")
.arg_from_usage("[scflag] -f --flag... 'tests flags'")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("[scpositional] 'tests positionals'"))
.get_matches();
Expand Down Expand Up @@ -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") {
Expand Down
Loading

0 comments on commit ace4f1a

Please sign in to comment.