Commit graph

858 commits

Author SHA1 Message Date
Hideyuki Tanaka
8cd120c230 Fix the behavior of require_delimiter 2016-10-04 18:40:03 -04:00
tormol
a214a34529 refactor(app::Parser) Replace continue and .push() with iterator adaptors 2016-10-04 19:15:18 +02:00
tormol
9679713a30 refactor(app::Help): Use map.values() and don't do if !foo when there is an else 2016-10-04 19:14:32 +02:00
tormol
7455d73404 refactor(app::Help): Replace str.split('\n') with str.lines() 2016-10-04 19:02:17 +02:00
Salim Afiune
905d3b9777 Fix linting errors from rustc 1.14.0
The new version of rustc 1.14.0-nightly (144af3e97 2016-10-02) has new
linting warnings/errors. This commit fixes them.

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
40d6dac973 feat(flag_aliases): Ability to alias flags
Added same alias funtionality for flags, now you can do:
```
Arg::with_name("flg")
    .long("flag")
    .short("f")
    .alias("not_visible_flag")
    .visible_alias("awesome_v_flag")
```

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
e5d9760bea Added Arg::(visible_)alias(es) docs
Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
33b5f6ef2c feat(arg_aliases): Ability to alias arguments
There are some cases where you need to have an argument to have an
alias, an example could be when you depricate one option in favor of
another one.

Now you are going to be able to alias arguments as follows:
```
Arg::with_name("opt")
    .long("opt")
    .short("o")
    .takes_value(true)
    .alias("invisible")
    .visible_alias("visible")
```

Closes #669
2016-10-04 12:26:51 -04:00
tormol
fd4c0870be refactor(UsageParser tests) Use VecMap's .values() instead of .iter().map(|(_,&v)| v)
In many cases this makes the assert fit on one line, but the double references are a bit awkward.
2016-09-30 17:29:31 +02:00
tormol
42a6d232d4 refactor(UsageParser::parse) merge two ifs 2016-09-30 17:29:31 +02:00
tormol
bb1fa0d694 refactor(UsageParser) Make the functions passed to .stop_at() straightforward 2016-09-30 17:29:31 +02:00
tormol
1d6a7c6e7e fix(UsageParser): Handle non-ascii names / options.
This should also speeds up the parser (except maybe for short options).
Multi-codepoint characters still can't be used as short options, but people shouldn't non-ASCII options nyway.

Closes #664
2016-09-30 17:29:23 +02:00
Nicolas Barbotte
bac417fa1c docs: typo 2016-09-20 09:47:50 +02:00
Kevin K
6b9bd215c1
docs(Default Values): adds better examples on using default values
Closes #418
2016-09-18 16:01:27 -04:00
Kevin K
c81bc722eb
docs: updates the docs about removing implicit value_delimiter(true) 2016-09-18 15:24:44 -04:00
Kevin K
09d4d0a903
fix(Value Delimiters): fixes the confusion around implicitly setting value delimiters. (default is now false)
Now if one wishes to use value delimiters, they must explicitly set `Arg::use_delimiter(true)` or
`Arg::require_delimiter(true)`. No other methods implicitly set this value.

Closes #666
2016-09-18 15:22:55 -04:00
Kevin K
92ac353b48
fix(Help Wrapping): fixes a regression-bug where the old {n} newline char stopped working
As of this commit, one can use the old newline character `{n}` or the new `\n`

Closes #661
2016-09-12 23:19:26 -04:00
Kevin K
a9699e4d7c
fix(AllowLeadingHyphen): fixes a bug where valid args aren't recognized with this setting
Closes #588
2016-09-12 21:48:50 -04:00
Kevin K
0dcfc77dae
tests(Debugging): standardizes certain debugging calls 2016-09-12 21:48:22 -04:00
Kevin K
8ffd7b827c Merge branch 'master' into issue-640 2016-09-11 13:00:04 -04:00
nabijaczleweli
945019654d
docs(appsettings): Document AppSetting::DisableVersion
Closes #589
2016-09-11 10:31:35 +02:00
Kevin K
9151ef7398 feat(Help): adds ability to hide the possible values on a per argument basis
Previously one could only hide the possible values of an argument application or command wide, and
not on a per argument basis. Now one can use the `Arg::hide_possible_values(bool)` method to hide
only that arguments possible values.

Closes #640
2016-09-10 23:07:15 -04:00
Kevin K
f9d17a060a docs(Value Delimiters): updates the docs for the Arg::multiple method WRT value delimiters and default settings 2016-09-10 18:23:31 -04:00
Kevin K
f9e692548e imp(Value Delimiters): changes the default value delimiter rules
Prior to this change, values were always delimited by default. This was causing issues with code
where the arg had a single value, and contained valid commas and shouldn't be delimited. This
commit changes the rules slightly so that values are not delimited by default, *unless* one of the
methods which implies multiple values was used (max_values, value_names, etc.).

This means single value args should *not* be delimited by default. If one wishes to use the old
way, they can add `Arg::use_delimiter(true)` to such code.

Closes #655
2016-09-10 18:19:33 -04:00
nabijaczleweli
a43e28af85
feat(help): allow for limiting detected terminal width
Useful when, e.g., the terminal is fullscreen

Closes #653
2016-09-10 21:19:35 +02:00
nabijaczleweli
a8afed7428
perf(help): fix redundant contains() checks
Addresses comments from c76785239f
2016-09-08 21:56:07 +02:00
Kevin K
2e99e22630 Merge branch 'master' into issue-617 2016-09-07 10:45:27 -04:00
Kevin K
c5a2b352ca docs(Help Wrapping): removes the verbage about using '{n}' to insert newlines in help text 2016-09-07 08:42:10 -04:00
Kevin K
c76785239f imp(Help Wrapping): clap now ignores hard newlines in help messages and properly re-aligns text, but still wraps if the term width is too small
Prior to this commit, clap would mangle help messages with hard newlines
(see #617). After this commit, clap will ignore hard newlines and treat
them like an inserted newline, properly wrapping and aligning text and
then restarting it's count until the next newline should be inserted.

This commit also removes the need for using `{n}` to insert a newline in
help text, now the traditional `\n` can be used. For backwards
compatibility, the `{n}` still works.

Closes #617
2016-09-07 08:38:26 -04:00
Aluísio Augusto Silva Gonçalves
b9b55a39df
imp(YAML): supports setting Arg::require_delimiter from YAML 2016-09-06 13:30:31 -03:00
Kevin K
0d503504d2 Merge branch 'master' of github.com:kbknapp/clap-rs 2016-09-05 22:12:12 -04:00
Kevin K
5658b117ae imp(Help Wrapping): makes some minor changes to when next line help is automatically used 2016-09-05 20:14:05 -04:00
Kevin K
01cae7990a imp(Help Wrapping): makes some minor changes to when next line help is automatically used 2016-09-05 19:51:14 -04:00
Kevin K
b246be1a4b style: rustfmt run 2016-09-05 17:03:45 -04:00
Kevin K
b3efc10751 fix(Settings): fixes an issue where settings weren't propogated down through grand-child subcommands
In some cases settings were only propogated down one level deep, this
commit ensures settings are propogated down through all subcommands
recursively.

Closes #638
2016-09-05 17:01:22 -04:00
Kevin K
07e6e8ea31 style: rustfmt run 2016-09-05 15:29:40 -04:00
Kevin K
956965cc94 chore: clippy run 2016-09-05 15:14:47 -04:00
Vinzent Steinberg
58512f2fcb feat(Errors): Errors with custom description
This is useful if a more meaningful message can be displayed to the
user with `Error::exit`. For example, if a file is not found, the
converted `io::Error` will give a message like:

    "error: entity not found"

With this, it is possible to replace this message with a more useful
one, like for instance:

    "error: configuration file not found"

Coloring is respected. Some duplication in the `From::from` impls was
reduced.
2016-09-05 14:54:14 -04:00
nabijaczleweli
fc7327e9dc
imp(help): use term_size instead of home-grown solution 2016-08-29 07:36:06 +02:00
Kevin K
b7793a2f4d Issues rollup (#637)
* feat: adds App::with_defaults to automatically use crate_authors! and crate_version! macros

One can now use

```rust
let a = App::with_defaults("My Program");

// same as
let a2 = App::new("My Program")
	.version(crate_version!())
	.author(crate_authors!());
```

Closes #600

* imp(YAML Errors): vastly improves error messages when using YAML

When errors are made while developing, the panic error messages have
been improved instead of relying on the default panic message which is
extremely unhelpful.

Closes #574

* imp(Completions): uses standard conventions for bash completion files, namely '{bin}.bash-completion'

Closes #567

* imp(Help): automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long

Now `clap` will check if it should automatically place long help
messages on the next line after the flag/option. This is determined by
checking to see if the space taken by flag/option plus spaces and values
doesn't leave enough room for the entirety of the help message, with the
single exception of of if the flag/option/spaces/values is less than 25%
of the width.

Closes #597

* tests: updates help tests to new forced new line rules

* fix(Groups): fixes some usage strings that contain both args in groups and ones that conflict with each other

Args that conflict *and* are in a group will now only display in the
group and not in the usage string itself.

Closes #616

* chore: updates dep graph

Closes #633

* chore: clippy run

* style: changes debug header to match other Rust projects

* chore: increase version
2016-08-27 23:42:31 -04:00
nabijaczleweli
85999ea7ad
docs(app): document that Windooze supports term width detection now 2016-08-26 17:18:24 +02:00
nabijaczleweli
0d93d9b953
feat(help): support wrapping help at console width on windows
Closes #455
2016-08-26 17:18:24 +02:00
Jędrzej
853a90de01 docs(app): fix documentation formatting for App::template() (#632) 2016-08-26 11:16:32 -04:00
nabijaczleweli
ecfda7d434
docs(arggroup): fix example not formatted as code 2016-08-26 12:40:38 +02:00
Kevin K
d0b442c7be fix(Help Wrapping): fixes a bug where help is wrapped incorrectly and causing a panic with some non-English characters
Closes #626
2016-08-25 18:50:13 -04:00
Kevin K
57690b2af1 chore: allows wrapping help on windows 2016-08-24 22:04:19 -04:00
Kevin K
763a5c920e fix(Unicode): fixes two bugs where non-English characters were stripped or caused a panic with help wrapping
Closes #626
2016-08-24 21:50:27 -04:00
Kevin K
00b8205d22 docs(Term Width): adds details about set_term_width(0) 2016-08-24 19:39:31 -04:00
Kevin K
7dfdaf200e feat(Help): adds new short hand way to use source formatting and ignore term width in help messages
Prior to this commit if one wished to use source formatting and ignore
term width they could do `App::set_term_width(usize::MAX)` now one can
also use `App::set_term_width(0)` which does the same thing.

Closes #625
2016-08-24 19:39:31 -04:00
Kevin K
a643fb283a fix: fixes a bug where the help is printed twice
Closes #623
2016-08-21 20:45:12 -04:00
Kevin K
9ade2cd4b2 feat(YAML): allows using lists or single values with arg declarations
One can now use a list or single value for certain Arg YAML declarations
such as possible_values, etc.

Prior to this commit, if only a single value was desired one would have
to use the format:

```yaml
possible_values:
    - value
```

But now once can use

```yaml
possible_values: value
```

Closes #614
Closes #613
2016-08-20 18:59:24 -04:00
Kevin K
7bc1b4b6c7 chore: clippy run 2016-08-20 17:52:03 -04:00
Kevin K
e203515e3a fix(Help Subcommand): fixes misleading usage string when using multi-level subcommmands
For example, doing `myprog help subcmd1 subcmd2` would have incorrectly
produced the usage string, `myprog subcmd2 [options]` but now correctly
prints `myprog subcmd1 subcmd2 [options]`

Closes #618
2016-08-20 17:17:58 -04:00
Jesús Espino
bba598931a Fix issue #607: Remove already matched parameters on errors of required 2016-08-06 00:08:31 +02:00
Kevin K
32dba379d4 Merge branch 'fix-subcommand-name' of https://github.com/starkat99/clap-rs into starkat99-fix-subcommand-name 2016-07-28 21:16:09 -04:00
Tshepang Lekhonkhobe
13233d7f2f doc: small fixes (#609) 2016-07-28 21:15:10 -04:00
Kevin K
ccdd0571c2 Merge branch 'fish-completion' of https://github.com/wdv4758h/clap-rs into wdv4758h-fish-completion 2016-07-27 21:15:39 -04:00
Kathryn Long
875df24316 fix(parser): preserve external subcommand name
BREAKING CHANGE: Access external subcommand arguments using an empty
argument name (i.e. `values_of("")`) instead of the previous subcommand
name.
2016-07-26 23:56:52 -05:00
Chiu-Hsiang Hsu
1979d2f2f3 feat(Completions): one can generate a basic fish completions script at compile time
The following completion would happen (using example 17_yaml.rs):

```
$ prog <tab>
help subcmd
```

```
$ prog -<tab><tab>
--help  -h                            (Prints help information)
--max-vals      (you can only supply a max of 3 values for me!)
--min-vals  (you must supply at least two values to satisfy me)
--mode                   (shows an option with specific values)
--mult-vals        (demos an option which has two named values)
--option  -o                (example option argument from yaml)
--version  -V                      (Prints version information)
-F                                         (demo flag argument)
```

```
$ prog --<tab><tab>
--help  -h                            (Prints help information)
--max-vals      (you can only supply a max of 3 values for me!)
--min-vals  (you must supply at least two values to satisfy me)
--mode                   (shows an option with specific values)
--mult-vals        (demos an option which has two named values)
--option  -o                (example option argument from yaml)
--version  -V                      (Prints version information)
```

```
$ prog --mode <tab>
emacs  (shows an option with specific values)  vi  (shows an option with specific values)
```

```
$ prog subcmd -<tab>
--help  -h        (Prints help information)  -B  (example subcommand option)
--version  -V  (Prints version information)
```

```
$ prog subcmd --<tab>
--help  (Prints help information)  --version  (Prints version information)
```

Close #578
2016-07-26 10:15:37 +08:00
Kevin K
7bf76b889b chore: clippy run 2016-07-25 20:56:22 -04:00
Barret Rennie
0ceba231c6 feat(Settings): Add unset_setting and unset_settings fns to App (#598)
Closes #590.
2016-07-24 00:08:24 -04:00
Roman A. Taycher
3398b64b5a Merge branch 'master' into authors 2016-07-23 16:39:29 -07:00
Roman A. Taycher
05edc4338e removed unstable gate from crate_authors 2016-07-23 15:56:42 -07:00
Kevin K
1fc3b55bd6 fix: fixes bug where only first arg in list of required_unless_one is recognized
Closes #575
2016-07-23 17:21:47 -04:00
Kevin K
fc72cdf591 fix(Settings): fixes typo subcommandsrequired->subcommandrequired
Closes #593
2016-07-23 16:25:17 -04:00
David Szotten
9f62cf7378 feat(Completions): adds the ability to generate completions to io::Write object 2016-07-14 09:38:13 +01:00
Bence Szigeti
8c32b4b63f Fix: missing color 2016-07-05 23:16:44 +02:00
Bence Szigeti
f8ca3085da Fix: typo -- missing space and commas 2016-07-05 22:14:47 +02:00
Bence Szigeti
8d7bea823f Fix: extra space typo removed 2016-07-05 22:01:04 +02:00
Mike Boutin
b3cdc3b5c2 Fix get_matches typo 2016-07-04 10:19:36 -04:00
Kevin K
cecfe981ea fix(Completions): fixes bug where --help and --version short weren't added to the completion list
Closes #563
2016-07-03 10:55:40 -04:00
Sébastien Watteau
722f2607be docs(Completions): fixes the formatting of the Cargo.toml excerpt in the completions example 2016-07-02 09:31:09 +02:00
Kevin K
57484b2dae imp(Completions): allows multiple completions to be built by namespacing with bin name
Completions are now written `<bin>_<shell>.<ext>` vice the old, `<shell>.<ext>`
2016-07-01 22:15:23 -04:00
Kevin K
96c24c9a8f fix(AllowLeadingHyphen): fixes an issue where isn't ignored like it should be with this setting
Prior to this fix, using `AppSettings::AllowLeadingHyphen` wouldn't properly ignore `--`

Closes #558
2016-07-01 13:47:41 -04:00
Kevin K
0ab9f84052 imp(Completions): completions now include aliases to subcommands, including all subcommand options
Aliases to subcommands can now be completed just like the original subcommand they alias.

Imagine a subcommand `update` with alias `install`, the `update` subcommand has an option `--pkg`
which accepts a package to update/install.

The following completion would happen:

```
$ prog <tab><tab>
-h --help -V --version install update

$ prog install <tab><tab>
-h --help -V --version --pkg

$ prog install --pkg <tab><tab>
$ prog install --pkg <PACKAGE>

$ prog update <tab><tab>
-h --help -V --version --pkg

$ prog update --pkg <tab><tab>
$ prog update --pkg <PACKAGE>
```

Closes #556
2016-07-01 12:57:37 -04:00
Kevin K
9b359bf062 docs(Completions): fixes some errors in the completion docs 2016-07-01 12:26:20 -04:00
Kevin K
18fc2e5b5a imp(Completions): completions now continue completing even after first completion
Prior to this change, completions only allowed one completion per command, this change allows as
many as required. The one downside to this change is the completion engine isn't smart enough to
determine which options are no longer legal after certain options have been applied.
2016-07-01 12:22:30 -04:00
Kevin K
89cc2026ba imp(Completions): allows matching on possible values in options
Now when one completes an option with possible values, those values will be displayed. Imagine
a program with an `--editor` option, which accepts either `vi`, or `emacs`. The following would
be displayed for completions

```
$ prog --editor <tab><tab>
vi emacs
```

Closes #557
2016-07-01 12:20:16 -04:00
Kevin K
7daee9ded0 chore: increase version 2016-07-01 00:34:08 -04:00
Kevin K
c6c519e40e docs(Completions): adds documentation for completion scripts 2016-07-01 00:18:52 -04:00
Kevin K
e75b6c7b75 feat(Completions): one can now generate a bash completions script at compile time
By using a build.rs "build script" one can now generate a bash completions script which allows tab
completions for the entire program, to include, subcommands, options, everything!

See the documentation for full examples and details.

Closes #376
2016-06-30 23:50:49 -04:00
Kevin K
ceddee9157 refactor(term.rs): moved term.rs into it's own crate so others can pull in just that portion
The functionality can now be found in https://crates.io/crates/term_size

Closes #549
2016-06-29 23:19:08 -04:00
Kevin K
49af4e38a5 docs(Arg): adds docs for 2016-06-29 23:00:50 -04:00
Kevin K
920b5595ed feat(Arg): adds new setting Arg::require_delimiter which requires val delimiter to parse multiple values
Using this setting requires a value delimiter be present in order to parse multiple values.
Otherwise it is assumed no values follow, and moves on to the next arg with a clean slate.

These examples demonstrate what happens when `require_delimiter(true)` is used. Notice
everything works in this first example, as we use a delimiter, as expected.

```rust
let delims = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true)
        .require_delimiter(true))
    // Simulate "$ reqdelims -o val1,val2,val3"
    .get_matches_from(vec![
        "reqdelims", "-o", "val1,val2,val3",
    ]);

assert!(delims.is_present("opt"));
assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
```
In this next example, we will *not* use a delimiter. Notice it's now an error.

```rust
let res = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true)
        .require_delimiter(true))
    // Simulate "$ reqdelims -o val1 val2 val3"
    .get_matches_from_safe(vec![
        "reqdelims", "-o", "val1", "val2", "val3",
    ]);

assert!(res.is_err());
let err = res.unwrap_err();
assert_eq!(err.kind, ErrorKind::UnknownArgument);
```
What's happening is `-o` is getting `val1`, and because delimiters are required yet none
were present, it stops parsing `-o`. At this point it reaches `val2` and because no
positional arguments have been defined, it's an error of an unexpected argument.

In this final example, we contrast the above with `clap`'s default behavior where the above
is *not* an error.

```rust
let delims = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true))
    // Simulate "$ reqdelims -o val1 val2 val3"
    .get_matches_from(vec![
        "reqdelims", "-o", "val1", "val2", "val3",
    ]);

assert!(delims.is_present("opt"));
assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
```
2016-06-29 22:57:28 -04:00
Josh Triplett
5d663d905c fix: Declare term::Winsize as repr(C)
The term module uses the struct Winsize directly in a C ioctl call, so
it must use C struct representation.
2016-06-29 17:22:31 -07:00
Kevin K
cdc500bdde fix(Options): values using delimiters no longer parse additional values after a trailing space
Imagine two args, an option `-o` which accepts mutliple values, and a positional arg `<file>`.
Prior to this change the following (incorrect) parses would have happened:

```
$ prog -o 1,2 some.txt
o = 1, 2, file
file =
```

Only when delimters are used, spaces stop parsing values for the option. The follow are now correct

```
$ prog -o 1,2 some.txt
o = 1, 2
file = some.txt

$ prog some.txt -o 1 2
o = 1, 2
file = some.txt
```

This still has the bi-product of:

```
$ prog -o 1 2 some.txt
o = 1, 2, some.txt
file =
```

This is simply a CLI design and documentation issue (i.e. don't allow options with unlimited
multiple values with positionaln args, or clearly document that positional args go first). This
will also be helped by the upcoming `Arg::require_delimiter`

Relates to #546
2016-06-29 13:21:30 -04:00
Kevin K
290f61d071 fix(Options): using options with an = no longer parse args after the trailing space as values
Imagine two args, an options `-o` and a positionanl arg `<file>` where the option allows multiple
values. Prior to this change the following (incorrect) parses were occurring:

```
$ prog -o=1 some.txt
o = 1, file
file =
```

This change stops parsing values at the space, only if the `=` was used.

```
$ prog -o=1 some.txt
o = 1
file = some.txt
```

Multiple values are still supported via value delimiters

```
$ prog -o=1,2 some.txt
o = 1, 2
file = some.txt
```

Relates to #546
2016-06-29 13:16:31 -04:00
Kevin K
edf9b2331c imp(arg_enum!): allows using meta items like repr(C) with arg_enum!s
One can now use more than one meta item, and things like `#[repr(C)]`

Example:

```rust

arg_enum! {
	#[repr(C)]
	#[derive(Debug)]
	pub enum MyEnum {
		A=1,
		B=2
	}
}

```

Closes #543
2016-06-28 00:09:25 -04:00
Homu
18237f403a Auto merge of #542 - brianp:issue-426, r=kbknapp
imp(ArgGroup): Add multiple ArgGroups per Arg

Add the function `Arg.groups` that can take a `Vec<&'a str>` to add the `Arg` to multiple `ArgGroup`'s at once.

ex:
```rust
Arg::with_name("arg")
    .groups(&["grp1", "grp2"])
```

Closes #426
2016-06-25 03:26:48 +09:00
Brian Pearce
902e182f7a imp(ArgGroup): Add multiple ArgGroups per Arg
Add the function `Arg.groups` that can take a `Vec<&'a str>` to add the `Arg` to multiple `ArgGroup`'s at once.

ex:
```rust
Arg::with_name("arg")
    .groups(&["grp1", "grp2"])
```

Closes #426
2016-06-24 08:57:11 -07:00
Roger Andersen
43b3d40b8c docs: fix typos 2016-06-24 12:23:08 +02:00
Kevin K
e84cc01836 fix(App): using App::print_help now prints the same as would have been printed by --help or the like
Using `App::print_help` before wasn't building the default `--help` and `--version` flags properly.
This has now been fixed.

Closes #536
2016-06-24 00:32:53 -04:00
Kevin K
9b2e45b170 imp(Usage Strings): [FLAGS] and [ARGS] are no longer blindly added to usage strings
In usage strings `[FLAGS]` and `[ARGS]` tags are now only added if there are relevant flags and
args to collapse. I.e. those that are

 * Not required (`[ARGS]` only)
 * Not belonging to some required group
 * Excludes --help and --version (`[FLAGS]` only)

Closes #537
2016-06-24 00:15:48 -04:00
Kevin K
e3d2893f37 fix(Help): prevents invoking <cmd> help help and displaying incorrect help message
Previously, if one ran `<cmd> help help` an additional `help` subcommand was created and a help
message displayed for it. We *could* have just thrown an error `<cmd> help help` but I worry that
the message would be confusing, because something like, "Invalid Subcommand" isn't 100% correct as
the form `<cmd> help <subcmd>` is allowed, and there *is* a `help` subcmd.

This fix correct dispatches `<cmd> help help` to the `<cmd>` help message.

Closes #538
2016-06-23 23:45:32 -04:00
Kevin K
08ad1cff4f fix(Help): subcommand help messages requested via <cmd> help <sub> now correctly match <cmd> <sub> --help
Prior to this fix, runnning `prog help subcmd` would produce:

```
subcmd

USGAE:
[...]
```

Notice lack of `prog-subcmd`. Whereas running `prog subcmd --help` produced:

```
prog-subcmd

USGAE:
[...]
```

These two forms now match the correct one (latter).

Closes #539
2016-06-23 21:47:30 -04:00
Kevin K
9e5f4f5d73 docs(Groups): vastly improves ArgGroup docs by adding better examples
Closes #534
2016-06-23 12:42:41 -04:00
Kevin K
33689acc68 feat(Groups): one can now specify groups which require AT LEAST one of the args
Unlike the previous ArgGroups, which made all args in the group mutually exclusive, one can now use
`ArgGroup::multiple(true)` which allows using more than one arg in the group (i.e. they're not all
mutually exclusive). When combined with `ArgGroup::required(true)` this effectively says, "At least
one of the args must be used, and using morethan one is also OK."

Closes #533
2016-06-23 12:40:08 -04:00
Kevin K
1f4da7676e fix(Help): App::before_help and App::after_help now correctly wrap
`before_help` and `after_help` weren't wrapping at the either the specified terminal width, or auto
determined one. That is now fixed.

Closes #516
2016-06-13 22:03:27 -04:00
Kevin K
1761dc0d27 feat(Help): allows wrapping at specified term width (Even on Windows!)
Now using `App::set_term_width` will set a wrapping width regardless of terminal size. This can
also be used when no terminal size can be determined (Such as on Windows). All help is now wrapped
at 120 if no terminal size has been specified, or can be determined.

Closes #451
2016-06-13 21:51:58 -04:00
Kevin K
e468faf3f0 fix(YAML): adds missing YAML methods for App and Arg
Closes #528
2016-06-12 22:10:25 -04:00
Kevin K
ca511de71f imp(Aliases): improves readability of asliases in help messages
Aliases are now displayed after the help text inside a `[aliases: als1, als2, als3]` style box.

Closes #526
Closes #529
2016-06-12 21:50:31 -04:00
Kevin K
7b10e7f893 feat(Subcommands): adds support for visible aliases
This commit adds support for visible aliases, which function exactly like aliases except that they
also appear in the help message, using the help string of the aliased subcommand.

i.e.

```rust
App::new("myprog")
    .subcommand(SubCommand::with_name("test")
		.about("does testy things")
		.alias("invisible")
		.visible_alias("visible"));
```

When run with `myprog --help`, the output is:

```
myprog

USAGE:
	myprog [FLAGS] [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help	        Prints this message or the help of the given subcommand(s)
    test|visible    does testy things
```

Closes #522
2016-06-09 21:55:35 -04:00
Kevin K
5354d14b51 fix(Subcommands): subcommands with aliases now display help of the aliased subcommand
Imagine subcommand `foo` had alias `bar`, running `myprog help bar` now correctly displays the help
for `foo`

Closes #521
2016-06-09 20:39:53 -04:00
Kevin K
1bfae42eaf refactor: clippy run 2016-06-08 00:10:56 -04:00
Kevin K
fc3e0f5afd feat(Settings): adds new setting to stop delimiting values with -- or TrailingVarArg
One can now use `AppSettings::DontDelimitTrailingValues` to stop clap's default behavior of
delimiting values, even when `--` or `TrailingVarArg` is used. This is useful when passing other
flags and commands through to another program.

Closes #511
2016-06-07 23:49:05 -04:00
Kevin K
7db45f78d8 chore: removes extra debug statements 2016-06-07 23:49:05 -04:00
Kevin K
706a7c11b0 fix(Settings): fixes bug where new color settings couldn't be converted from strs 2016-06-07 23:49:05 -04:00
Kevin K
01e7dfd6c0 fix(Windows): fixes a failing windows build 2016-06-07 20:49:18 -04:00
Kevin K
ec86f2dada imp(Usage Strings): improves the default usage string when only a single positional arg is present
Instead of blindly printing `[ARGS]` when only a single positional arg is present, it will now
print `[NAME]` (or `[NAME]...` for multiple values allowed)

Closes #518
2016-06-04 11:55:47 -04:00
Kevin K
e23418351a feat(Settings): one can now set an AppSetting which is propogated down through child subcommands
Closes #519
2016-06-04 11:55:47 -04:00
Kevin K
cd44080650 fix: fixes bug where args are printed out of order with templates 2016-06-04 11:55:47 -04:00
Kevin K
8f630c6a07 fix: fixes bug where one can't override version or help flags
Closes #514
2016-06-04 11:55:47 -04:00
Kevin K
330e5edf04 fix: fixes issue where before_help wasn't printed 2016-06-04 11:55:47 -04:00
Kevin K
054f8cb433 imp: removes extra newline from help output 2016-06-04 11:55:47 -04:00
Kevin K
c5b24c0eb0 tests: removes extra newline from version output tests 2016-06-04 11:28:24 -04:00
Kevin K
a7401dc6a1 imp: allows printing version to any io::Write object 2016-06-04 11:28:24 -04:00
Kevin K
cda27469cd imp: removes extra newline when printing version 2016-06-04 11:28:24 -04:00
Kevin K
65c2350aa3 feat: colors dont get sent to pipes by default
Color are now only used when outputting to a termainal/TTY. There are three new settings as well
which can be used to control color output, they are:

 * `AppSettings::ColorAuto`: The default, and will only output color when outputting to a terminal or TTY
 * `AppSettings::ColorAlways`: Outputs color no matter where the output is going
 * `AppSettings::ColorNever`: Never colors output

This now allows one to use things like command line options, or environmental variables to turn
colored output on/off.

Closes #512
2016-06-04 11:28:03 -04:00
Kevin K
3312893dda docs: inter-links all types and pages
All doc pages should now be inter-linked between other doc pages and
Rust documentation.

Closes #505
2016-05-15 14:23:37 -04:00
Kevin K
52ca6505b4 docs: makes all publicly available types viewable in docs
Some types weren't viewable in the docs, such as `Values`, `OsValues`,
and `ArgSettings`. All these types should now be browsable in the
docs page.

Relates to #505
2016-05-13 18:52:29 -04:00
Hendrik Sollich
ac42f6cf0d Fix: SubCommand::aliases lifetime errors 2016-05-11 21:08:25 +02:00
Hendrik Sollich
6ba910e89b test: adds failing doc test 2016-05-11 20:16:56 +02:00
Kevin K
41a482cf5d imp(SubCommand Aliases): adds feature to yaml configs too 2016-05-10 17:15:06 -04:00
Kevin K
66b4dea65c feat(SubCommands): adds support for subcommand aliases
Allows adding a subcommand alias, which function as "hidden" subcommands that automatically
dispatch as if this subcommand was used. This is more efficient, and easier than creating
multiple hidden subcommands as one only needs to check for the existing of this command,
and not all vairants.

Example:

```
let m = App::new("myprog")
            .subcommand(SubCommand::with_name("test")
                .alias("do-stuff"))
            .get_matches_from(vec!["myprog", "do-stuff"]);
assert_eq!(m.subcommand_name(), Some("test"));
```

Example using multiple aliases:

```
let m = App::new("myprog")
            .subcommand(SubCommand::with_name("test")
                .aliases(&["do-stuff", "do-tests", "tests"]))
            .get_matches_from(vec!["myprog", "do-tests"]);
assert_eq!(m.subcommand_name(), Some("test"));
```

Closes #469
2016-05-10 15:21:19 -04:00
Kevin K
3ca0947c16 fix(Usage Strings): now properly dedups args that are also in groups
For example, if an arg is part of a required group, it will only appear
in the group usage string, and not in both the group as well as the arg
by itself.

Imagine a group containing two args, `arg1` and `--arg2`

OLD:
    `myprog <arg1> <arg1|--arg2>`

NEW:
    `myprog <arg1|--arg2>`

Closes #498
2016-05-09 19:14:11 -04:00
Kevin K
f574fb8a7c fix(Usage Strings): removes duplicate groups from usage strings 2016-05-09 19:14:11 -04:00
Kevin K
852e58156c tests: removes old python tests and replaces with rust tests
Closes #166
2016-05-09 19:14:11 -04:00
Kevin K
fef11154fb imp(Groups): formats positional args in groups in a better way 2016-05-08 21:33:27 -04:00
Kevin K
03dfe5ceff imp(Help): moves positionals to standard <> formatting 2016-05-08 20:37:51 -04:00
Kevin K
2efd81ebbc chore: clippy update and run 2016-05-06 17:59:52 -04:00
Kevin K
ffde90f2ba style: rustfmt run 2016-05-06 17:52:23 -04:00
Kevin K
5b7fe8e416 imp(Help): default help subcommand string has been shortened
Closes #494
2016-05-05 21:49:51 -04:00
Kevin K
5b0120088a fix(Required Args): fixes issue where missing required args are sometimes duplicatd in error messages
Closes #492
2016-05-03 16:31:55 -04:00
Kevin K
d8e4dbc961 feat(Help): adds support for displaying info before help message
Can now use the `App::before_help` method to add additional information
that will be displayed prior to the help message. Common uses are
copyright, or license information.
2016-05-03 16:31:55 -04:00
Kevin K
9fdad2e970 tests: adds tests for required_unless settings 2016-05-03 16:31:54 -04:00
Kevin K
7c89fc55ff docs(required_unless): adds docs and examples for required_unless 2016-05-03 16:31:54 -04:00
Kevin K
6987f37e71 feat(Required): adds allowing args that are required unless certain args are present
Adds three new methods of `Arg` which allow for specifying three new
types of rules.

* `Arg::required_unless`

Allows saying a particular arg is only required if a specific other arg
*isn't* present.

* `Arg::required_unless_all`

Allows saying a particular arg is only required so long as *all* the
following args aren't present

* `Arg::required_unless_one`

Allows saying a particular arg is required unless at least one of the
following args is present.
2016-05-03 16:31:54 -04:00
Kevin K
cb708093a7 docs: hides formatting from docs 2016-05-02 18:04:10 -04:00
Kevin K
4fe133d9ce chore: removes unused imports 2016-05-02 18:04:10 -04:00
Kevin K
770397bcb2 feat(HELP): implements optional colored help messages
To enable, ensure `clap` is compiled with `color` cargo feature.

Then in code use `AppSettings::ColoredHelp`

Closes #483
2016-04-18 00:05:43 -07:00
Homu
fdbd12e830 Auto merge of #478 - hgrecco:template, r=kbknapp
A new Help Engine with templating capabilities

This set of commits brings a new Help System to CLAP.

Major changes are:
- The help format is (almost) completely defined in `help.rs` instead of being scattered across multiple files.
- The HELP object contains a writer and its methods accept AnyArgs, not the other way around.
- A template option allows the user to change completely the organization of the autogenerated help.
2016-04-18 08:12:39 +09:00
Hernan Grecco
627ae38dc0 refactor(HELP): Removed code for old help system and tests that helped with the transitions 2016-04-13 07:21:21 -03:00
Hernan Grecco
8d23806bd6 fix(HELP): Adjust Help to semantic changes introduced in 6933b84 2016-04-13 07:06:23 -03:00
Hernan Grecco
81e121edd6 feat(HELP): Add a Templated Help system.
The strategy is to copy the template from the the reader to wrapped stream
until a tag is found. Depending on its value, the appropriate content is copied
to the wrapped stream.
The copy from template is then resumed, repeating this sequence until reading
the complete template.

Tags arg given inside curly brackets:
Valid tags are:
    * `{bin}`         - Binary name.
    * `{version}`     - Version number.
    * `{author}`      - Author information.
    * `{usage}`       - Automatically generated or given usage string.
    * `{all-args}`    - Help for all arguments (options, flags, positionals arguments,
                        and subcommands) including titles.
    * `{unified}`     - Unified help for options and flags.
    * `{flags}`       - Help for flags.
    * `{options}`     - Help for options.
    * `{positionals}` - Help for positionals arguments.
    * `{subcommands}` - Help for subcommands.
    * `{after-help}`  - Help for flags.
2016-04-13 07:06:23 -03:00
Hernan Grecco
04b5b074d1 refactor(HELP): A new Help Engine
The largest organizational change is that methods used to generate the help are
implemented by the Help object and not the App, FlagBuilder, Parser, etc.

The new code is based heavily on the old one with a few minor modifications
aimed to reduce code duplication and coupling between the Help and the rest
of the code.

The new code turn things around: instead of having a HelpWriter that holds an
AnyArg object and a method that is called with a writer as argument,
there is a Help Object that holds a writer and a method that is called with a
writer as an argument.

There are still things to do such as moving `create_usage` outside the Parser.

The peformance has been affected, probably by the use of Trait Objects. This
was done as a way to reduce code duplication (i.e. in the unified help code).
This performance hit should not affect the usability as generating and printing
the help is dominated by user interaction and IO.

The old code to generate the help is still functional and is the active one.
The new code has been tested against the old one by generating help strings
for most of the examples in the repo.
2016-04-13 07:06:23 -03:00
Hernan Grecco
a91d378ba0 imp(parser.rs): Provide a way to create a usage string without the USAGE: title 2016-04-13 07:06:22 -03:00
Hernan Grecco
9d757e8678 imp(macros.rs): Added write_nspaces macro (a new version of write_spaces)
`write_nspaces` has three differences with `write_spaces`

  1. Accepts arguments with attribute access (such as self.writer)
  2. The order of the arguments is swapped to make the writer the first
      argument as in other write related macros.
  3. Does not use the `write!` macro under the hood but rather calls
      directly `write`

I have chosen to put the function under a new name to avoid backwards
compatibility problem but it might be better to migrate everything to
`write_nspaces` (and maybe rename it `write_spaces`)
2016-04-13 07:06:22 -03:00
Hernan Grecco
65b3f66753 imp(srs/args): Added longest_filter to AnyArg trait
This function allows providing an extra filter to remove elements when finding
the longest element.
2016-04-13 07:06:22 -03:00
Hernan Grecco
d51945f8b8 imp(parser.rs): Make Parser's create_usage public allowing to have function outside the parser to generate the help 2016-04-13 07:06:22 -03:00
Hernan Grecco
9b23e7ee40 imp(parser.rs): Expose Parser's flags, opts and positionals argument as iterators
Writing the help requires read only access to Parser's flags, opts
and positionals. This commit provides 3 functions returning iterators
over those collections (`iter_*`) allowing to have function outside
the parser to generate the help.
2016-04-13 07:06:22 -03:00
Hernan Grecco
1321630ef5 imp(src/args): Exposes argument display order by introducing a new Trait
This commit introduces a new trait (`DispOrder`) with a single function
(`fn disp_order(&self) -> usize`). It is use to expose the display order
of an argument in a read-only manner.
2016-04-13 07:06:22 -03:00
Roman A. Taycher
d0f1d204a0 minor comment fixes 2016-04-11 22:37:36 -07:00
Roman A. Taycher
38fb59abf4 feat(Authors Macro): adds a crate_authors macro
Adds a crate_authors! macro that fetches
crate authors from a (recently added)
cargo enviromental variable populated
from the Cargo file. Like the
crate_version macro.

Closes #447
2016-04-11 16:17:44 -07:00
panicbit
3019a685ee Fix off-by-one-error in ArgGroup printing 2016-04-10 02:46:51 +02:00
Kevin K
71acf1d576 fix(Help Message): fixes bug where arg name is printed twice
Closes #472
2016-04-02 20:35:49 -04:00
Holger Rapp
4c676c06e8 Use ::std::result::Result to make macro hygienic. 2016-04-01 22:03:29 +02:00
Kevin K
885d166f04 fix(Empty Values): fixes bug where empty values weren't stored
Passing empty values, such as `--feature ""` now stores the empty string
correctly as a value (assuming empty values are allowed as per the arg
configuration)

Closes #470
2016-03-29 22:25:13 -04:00
Kevin K
d4b5545099 fix: fixes compiling with debug cargo feature 2016-03-29 22:24:34 -04:00
Kevin K
205b07bf2e fix(Help Subcommand): fixes issue where help and version flags weren't properly displayed
Closes #466
2016-03-28 11:26:56 -04:00
Kevin K
05365ddcc2 fix(Help Message): fixes bug with wrapping in the middle of a unicode sequence
Closes #456
2016-03-27 16:01:17 -04:00
Kevin K
6933b8491c fix(Usage Strings): fixes small bug where -- would appear needlessly in usage strings
Closes #461
2016-03-27 14:22:51 -04:00
Kevin K
144e7e29d6 chore: clippy run 2016-03-22 21:16:53 -04:00
Kevin K
813d75d06f feat(Help Message): wraps and aligns the help message of subcommands
Subcommand's help strings are now automatically wrapped and aligned just
like other arguments.

Closes #452
2016-03-16 10:17:00 -04:00
Kevin K
1d73b03552 fix(Help Message): fixes a bug where small terminal sizes causing a loop
Now if the terminal size is too small to properly wrap the help text
lines, it will default to just wrapping normalling as it should.

This is determined on a per help text basis, so because the terminal
size is too small for a single argument's help to wrap properly, all
other arguments will still wrap and align correctly. Only the one
affected argument will not align properly.

Closes #453
2016-03-16 08:55:42 -04:00
Kevin K
2c12757bbd feat(Help Subcommand): adds support passing additional subcommands to help subcommand
The `help` subcommand can now accept other subcommands as arguments to
display their help message. This is similar to how many other CLIs
already perform. For example:

```
$ myprog help mysubcmd
```

Would print the help message for `mysubcmd`. But even more, the `help`
subcommand accepts nested subcommands as well, i.e. a grandchild
subcommand such as

```
$ myprog help child grandchild
```

Would print the help message of `grandchild` where `grandchild` is a
subcommand of `child` and `child` is a subcommand of `myprog`.

Closes #416
2016-03-14 22:41:47 -04:00
Kevin K
031b71733c chore: fixes platform dependant libc calls 2016-03-14 08:00:11 -04:00
Kevin K
d46eaa2cd6 style: fix formatting 2016-03-14 07:53:23 -04:00
Kevin K
675c39f8ba tests: moves app settings tests to the proper place 2016-03-13 22:07:28 -04:00
Kevin K
e428bb6d84 tests: moves some \t tabs to four spaces for consistency 2016-03-13 22:07:28 -04:00
Kevin K
e36af02666 feat(Help Message): can auto wrap and aligning help text to term width
By default `clap` now automatically wraps and aligns help strings to the
term width. i.e.

```
    -o, --option <opt>    some really long help
text that should be auto aligned but isn't righ
t now
```

Now looks like this:

```
    -o, --option <opt>    some really long help
                          text that should be
                          auto aligned but isn't
                          right now
```

The wrapping also respects words, and wraps at spaces so as to not cut
words in the middle.

This requires the `libc` dep which is enabled (by default) with the
`wrap_help` cargo feature flag.

Closes #428
2016-03-13 22:07:28 -04:00
Kevin K
c5c58c86b9 fix(From Usage): fixes a bug where adding empty lines werent ignored 2016-03-10 16:36:23 -05:00
Kevin K
22000a08f7 chore: changes some assertions to debug assertions 2016-03-10 16:33:39 -05:00
Kevin K
ad86e43334 feat(Settings): adds support for automatically deriving custom display order of args
Args and subcommands can now have their display order automatically
derived by using the setting `AppSettings::DeriveDisplayOrder` which
will display the args and subcommands in the order that they were
declared in, instead of alphabetical order which is the default.

Closes #444
2016-03-10 16:32:02 -05:00
Kevin K
927d1da1c7 chore: ignore failing clippy build 2016-03-09 19:54:42 -05:00
Kevin K
06c729f52f chore: fixes failing nightly lint 2016-03-09 18:40:31 -05:00
Kevin K
4ff0205b85 docs(Groups): explains required ArgGroups better
Closes #439
2016-03-09 20:16:52 -05:00
Kevin K
e41a2f1bea test: fixes failing doc tests 2016-03-09 20:14:35 -05:00
Kevin K
7d2a2ed413 feat(Subcommands): adds support for custom ordering in help messages
Allows custom ordering of subcommands within the help message. Subcommands with a lower
value will be displayed first in the help message. This is helpful when one would like to
emphasise frequently used subcommands, or prioritize those towards the top of the list.
Duplicate values **are** allowed. Subcommands with duplicate display orders will be
displayed in alphabetical order.

**NOTE:** The default is 999 for all subcommands.

```rust
use clap::{App, SubCommand};
let m = App::new("cust-ord")
    .subcommand(SubCommand::with_name("alpha") // typically subcommands are grouped
                                               // alphabetically by name. Subcommands
                                               // without a display_order have a value of
                                               // 999 and are displayed alphabetically with
                                               // all other 999 subcommands
        .about("Some help and text"))
    .subcommand(SubCommand::with_name("beta")
        .display_order(1)   // In order to force this subcommand to appear *first*
                            // all we have to do is give it a value lower than 999.
                            // Any other subcommands with a value of 1 will be displayed
                            // alphabetically with this one...then 2 values, then 3, etc.
        .about("I should be first!"))
    .get_matches_from(vec![
        "cust-ord", "--help"
    ]);
```

The above example displays the following help message

```
cust-ord

USAGE:
    cust-ord [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    beta    I should be first!
    alpha   Some help and text
```

Closes #442
2016-03-09 19:43:53 -05:00
Kevin K
9803b51e79 feat(Opts and Flags): adds support for custom ordering in help messages
Allows custom ordering of args within the help message. Args with a lower value will be
displayed first in the help message. This is helpful when one would like to emphasise
frequently used args, or prioritize those towards the top of the list. Duplicate values
**are** allowed. Args with duplicate display orders will be displayed in alphabetical
order.

**NOTE:** The default is 999 for all arguments.

**NOTE:** This setting is ignored for positional arguments which are always displayed in
index order.

```rust
use clap::{App, Arg};
let m = App::new("cust-ord")
    .arg(Arg::with_name("a") // typically args are grouped by alphabetically by name
                             // Args without a display_order have a value of 999 and are
                             // displayed alphabetically with all other 999 args
        .long("long-option")
        .short("o")
        .takes_value(true)
        .help("Some help and text"))
    .arg(Arg::with_name("b")
        .long("other-option")
        .short("O")
        .takes_value(true)
        .display_order(1)   // Let's force this arg to appear *first*
                            // all we have to do is give it a value lower than 999
                            // any other args with a value of 1 would be displayed
                            // alphabetically with other 1 args. Then 2, then 3, etc.
        .help("I should be first!"))
    .get_matches_from(vec![
        "cust-ord", "--help"
    ]);
```

The above example displays the following help message

```
cust-ord

USAGE:
    cust-ord [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -O, --other-option <b>    I should be first!
    -o, --long-option <a>     Some help and text
```
2016-03-09 19:41:43 -05:00
Alexander Bulaev
150784ae20 Update VecMap to 0.6 2016-03-08 19:50:20 -05:00
Kevin K
deace34ad2 chore: clippy run 2016-03-08 10:39:43 -05:00
Jorge Aparicio
56d14cbbb6 fix clippy warnings 2016-02-22 18:36:57 -05:00
Jorge Aparicio
6c851f4314 sprinkle #[derive(Copy)] 2016-02-21 11:45:19 -05:00
Jorge Aparicio
9a94ad8ad6 sprinkle #[allow(missing_debug_implementations)] 2016-02-21 11:44:45 -05:00
Jorge Aparicio
d752c17029 rename OsStrExt2::{is_empty,len} to {is_empty_,len_}
OsStr recently gained unstable inherent methods with the same name. This rename
makes sure we don't call the inherent methods but the methods provided by this
extension trait.
2016-02-21 11:18:26 -05:00
Kevin K
a834ae6990 chore: hides ArgSettings in docs 2016-02-19 01:47:37 -05:00
Kevin K
3c8db0e9be docs(AppSettings): clarifies that AppSettings do not propagate
Closes #429
2016-02-19 01:47:37 -05:00
Kevin K
e2ec5f09eb chore: clippy run 2016-02-19 01:47:37 -05:00
Kevin K
1e79cccc12 docs(Arg Examples): adds better examples 2016-02-19 01:47:37 -05:00
Kevin K
066df7486e imp(Help): adds setting for next line help by arg
Adds a setting for both `AppSettings` and an `Arg` method which allows
placing the help text for a particular argument (or all arguments via
the `AppSettings`) on the line after the argument itself and indented
once.

This is useful for when a single argument may have a very long
invocation flag, or many value names which throws off the alignment of
al other arguments. On a small terminal this can be terrible. Placing
the text on the line below the argument solves this issue. This is also
how many of the GNU utilities display their help strings for individual
arguments.

The final caes where this can be hepful is if the argument has a very
long or detailed and complex help string that will span multiple lines.
It can be visually more appealing and easier to read when those lines
don't wrap as frequently since there is more space on the next line.

Closes #427
2016-02-17 23:47:27 -05:00
Kevin K
b37c010c1b imp(Default Values): displays the default value in the help text 2016-02-14 01:11:06 -05:00
Kevin K
1153e8af60 chore: clippy run 2016-02-14 01:10:44 -05:00
Kevin K
9facd74f84 docs(Default Values): adds better examples and notes for default values 2016-02-10 12:39:44 -05:00
Kevin K
7321195296 feat(Defult Values): adds support for default values in args
Closes #418
2016-02-10 10:56:58 -05:00
Kevin K
5460778f56 tests: adds tests for displaying positional args with value names 2016-02-09 09:29:23 -05:00
Kevin K
f0a99916c5 imp(Positional Arguments): now displays value name if appropriate
When value names are use, they will be displayed in help and error
messages instead of the argument name. For example, an argument named
`arg` but with the value name `FILE` will be displayed as `[FILE]`.
Likewise multiple value names will be displayed properly such as `[FILE1] [FILE2]`

Closes #420
2016-02-09 09:27:17 -05:00
Kevin K
26f2e5feb0 tests(Multiple Values): fixes failing benches and adds tests to guard 2016-02-04 22:15:10 -05:00
Kevin K
72c387da0b fix(Multiple Values): fixes bug where number_of_values wasnt respected
i.e. assume, option -O set to multiple, and number_of_values(1)
set. And assume a *required* positional argument is also set.

-O some -O other pos

Would fail with pos arg not supplied.

Relates to #415
2016-02-04 19:38:17 -05:00
Kevin K
a62e452754 fix(AppSettings): fixes bug where subcmds didn't receive parent ver
Subcommands now receive the parent version when the setting
AppSettings::GlobalVersion has been set.
2016-02-04 11:54:46 -05:00
Kevin K
8bcbce27f7 tests(Suggestions): adds additional tests 2016-02-04 02:01:10 -05:00
Kevin K
7166f4f110 refactor(macros): removes ok() from Result.ok().expect() 2016-02-04 02:01:10 -05:00
Kevin K
2bc1908320 tests(ArgGroup): adds additional tests including YAML 2016-02-04 02:01:10 -05:00
Kevin K
fcbc7e12f5 fix: adds support for building ArgGroups from standalone YAML
ArgGroups can now be built from standalone YAML documents. This is
labeled as a fix because it should have been the case prior. A
standalone YAML document for a group would look something like

```
name: test
args:
    - arg1
    - arg2
required: true
conflicts:
    - arg3
requires:
    - arg4
```

This commit also keeps support building groups as part of a larger
entire App YAML document where the name is specified as a key to the
yaml tree
2016-02-04 02:01:10 -05:00
Alex Hill
85b11468b0 fix: Stop lonely hyphens from causing panic
The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.

Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.

This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410
2016-02-02 21:05:45 -08:00
Kevin K
c19a791745 imp(values): adds support for up to u64::max values per arg 2016-02-02 07:45:49 -05:00
Kevin K
d431417003 refactor(macros): does some code deduplication by macros 2016-02-02 07:45:49 -05:00
Kevin K
2704b300ec refactor(macros): implements a slightly better arg_post_processing 2016-02-02 07:45:49 -05:00
Kevin K
8f145f1024 refactor(macros): implements a better _handle_group_reqs 2016-02-02 07:45:49 -05:00
Kevin K
de32078d75 refactor(macros): implements a better vec_remove and remove_overriden 2016-02-02 07:45:49 -05:00
Kevin K
ca7f197a12 refactor: minor code cleanup 2016-02-02 07:45:49 -05:00
Kevin K
cdee7a0eb2 feat(AppSettings): adds HidePossibleValuesInHelp to skip writing those values 2016-02-02 07:21:01 -05:00
Kevin K
be2cbd9480 fix(App::args_from_usage): skips empty lines when parsing multiple lines from usage 2016-02-02 07:21:01 -05:00
Kevin K
ee96baffd3 fix(value_t_or_exit): fixes typo which causes value_t_or_exit to return a Result 2016-02-02 07:21:01 -05:00
Ceri Storey
3731ddb361 fix(matched_arg): Allow for more than 256 occurrences of an argument. 2016-02-02 19:30:32 +00:00
Kevin K
ab41be700b imp(arg_enum): enum declared with arg_enum returns [&'static str; #] instead of Vec 2016-01-31 08:23:34 -05:00
Kevin K
c19c17a885 fix(SubCommands): fixed where subcmds weren't recognized after mult args
Closes #405
2016-01-31 07:35:42 -05:00
Kevin K
0bcc712064 fix(Usage Parser): fixes a bug where literal single quotes weren't allowed in help strings
Closes #406
2016-01-31 07:12:07 -05:00
Vincent Prouillet
0c8b84af61 fix: clap_app! should be gated by unstable, not nightly feature 2016-01-30 11:16:13 +00:00
Kevin K
90542747ac chore: fixes doc and style mistakes 2016-01-28 21:58:40 -05:00
Kevin K
c28d24db3e fix: fixes nightly build with new lints 2016-01-28 11:46:12 -05:00
Kevin K
d182049119 chore: fixes failing rustdoc 2016-01-28 11:46:12 -05:00
Kevin K
a210f89b84 docs: updates examples for 2x release
Closes #394
2016-01-28 11:46:12 -05:00
Kevin K
518b89bd3d fix: fixes Windows build for 2x release
Closes #392
2016-01-28 11:46:12 -05:00
Kevin K
2031682193 chore: updates additional files for 2x release 2016-01-28 11:46:12 -05:00
Kevin K
d2a78e3e21 docs: updates documentation for v2 release 2016-01-28 11:45:31 -05:00
Kevin K
693aece2cb fix: fixes yaml build for 2x base 2016-01-28 11:45:31 -05:00
Kevin K
4c37b26a84 tests: fixes some failing doc tests 2016-01-28 11:45:31 -05:00
Kevin K
e494672ffc refactor: removes some unnecessary code checks 2016-01-28 11:45:31 -05:00
Kevin K
f1876388a7 docs: updating docs for 2x release 2016-01-28 11:45:31 -05:00
Kevin K
609c06e119 feat: adds support for external subcommands
External subcommands are now supported via the following:

```rust
extern crate clap;
use clap::{App, AppSettings};

fn main() {
    // Assume there is a third party subcommand named myprog-subcmd
    let m = App::new("myprog")
        .setting(AppSettings::AllowExternalSubcommands)
        .get_matches_from(vec![
            "myprog", "subcmd", "--option", "value", "-fff", "--flag"
        ]);
    // All trailing arguments will be stored under the subcommands sub-matches under a
    // value of their runtime name (in this case "subcmd")
    match m.subcommand() {
        (external, Some(ext_m)) => {
            let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
            assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
        },
        _ => unreachable!()
   }
}
```

Closes #372
2016-01-28 11:45:31 -05:00
Kevin K
86f3e33975 refactor(macros): uses macros to implement Settings enums 2016-01-28 11:45:31 -05:00
Kevin K
26ecadd252 feat: adds support values with a leading hyphen
By using AppSettings::AllowLeadingHyphen values starting with a
leading hyphen (such as a negative number) are supported. This
setting should be used with caution as it silences certain
circumstances which would otherwise be an error (like forgetting
a value to an option argument).

Closes #385
2016-01-28 11:45:31 -05:00
Kevin K
35ad17a282 feat: adds support for turning off the value delimiter
Closes #352
2016-01-28 11:45:31 -05:00
Kevin K
0871145245 feat: adds support changing the value delimiter
Closes #353
2016-01-28 11:45:31 -05:00
Kevin K
c2e03a0a4e feat: adds support for comma separated values
This commit adds support for values separated by commas such as
--option=val1,val2,val3. It also includes support for uses
without the equals and shorts (both with and without)

--option=val1,val2
--option val1,val2
-oval1,val2
-o=val1,val2
-o val1,val2

Closes #348
2016-01-28 11:45:31 -05:00
Kevin K
4192e1acea test(Yaml): fixes yaml tests 2016-01-28 11:45:31 -05:00
Kevin K
eb4de9215f imp(From Usage): vastly improves the usage parser
Closes #350
2016-01-28 11:45:31 -05:00
Kevin K
95e8209712 feat: adds support with options with optional values
Closes #367
2016-01-28 11:45:31 -05:00
Kevin K
0eba835968 tests: updated python tests to v2 info 2016-01-28 11:45:31 -05:00
Kevin K
d707fa0fad tests(v2): updating yaml tests to new v2 base 2016-01-28 11:45:31 -05:00
Kevin K
0410873d8d chore: clippy run 2016-01-28 11:45:31 -05:00
Kevin K
bb52d2d194 chore: removes unneeded function 2016-01-28 11:45:31 -05:00
Kevin K
e874a0d5e0 feat(UTF-8): adds support for invalid utf8 in values
Closes #269
2016-01-28 11:45:31 -05:00
Kevin K
c3e96232c9 tests(v2): fixing more tests on the new v2 base 2016-01-28 11:45:31 -05:00
Kevin K
0031d78564 refactor(v2): improving macros for code dedup 2016-01-28 11:45:31 -05:00
Kevin K
7fc18e685f test(v2): fixing tests to pass under new v2 changes 2016-01-28 11:45:31 -05:00
Kevin K
20de5c6e76 feat(v2): implementing the base of 2.x
This commit implements the base changes for clap 2.x
2016-01-28 11:45:31 -05:00
Kevin K
d3a4834225 chore: fix failing nightly 2016-01-27 10:09:29 -05:00
messense
f0a0e4df50 docs(App) Fix App.print_help documentation 2016-01-10 16:44:24 +08:00
Kevin K
c9bf7e4440 fix: fixes an issue where invalid short args didn't cause an error
Closes #368
2016-01-03 22:54:13 -05:00