Commit graph

858 commits

Author SHA1 Message Date
Kevin K
b4f2e2a1b6
chore: clippy run 2016-11-11 15:48:40 -05:00
Kevin K
55e7385685
style: changes try! to ? and rustfmt run 2016-11-11 15:20:07 -05:00
Arnavion
5869ebbffc Completion support for PowerShell.
Fixes #729
2016-11-05 02:47:23 -07:00
Kevin K
33924e8844
fix(Low Index Multiples): fixes a bug where using low index multiples was propgated to subcommands
Closes #725
2016-11-01 23:31:29 -04:00
Kevin K
61bde461e1
chore: clippy run 2016-11-01 18:42:03 -04:00
Kevin K
1ced2a7433
feat(Positional Args): allows specifying the second to last positional argument as multiple(true)
Now one can build CLIs that support things like `mv <files>... <target>`

There are a few requirements and caveats;

 * The final positional argument (and all positional arguments prior) *must* be required
 * Only one positional argument may be `multiple(true)`
 * Only the second to last, or last positional argument may be `multiple(true)`

Closes #725
2016-11-01 16:25:54 -04:00
Kevin K
1d6f8fd7de
chore(Completion Error): changes error message to reflect not only BASH is supported 2016-11-01 16:25:47 -04:00
Matthias Beyer
bc2075d088 Add App::app_name() getter 2016-11-01 20:11:26 +01:00
Kevin K
3d37001d1d
imp(Error Output): conflicting errors are now symetrical, meaning more consistent and less confusing
Prior to this commit, conflicting error messages and the suggeseted usage would depend on whether
you defined the conflict on both arguments, or just one, and the order in which you specified the
conflicting arguments at runtime.

Now they are symetrical, meaning the suggestions from the error message are consistent, and it no
longer matters if you specify the conflict in one, or both arguments.

Closes #718
2016-10-31 00:35:23 -04:00
Kevin K
5c70e1a01b
fix(ZSH Completions): fixes bug that caused panic on subcommands with aliases
ZSH completions now fully support subcommands with aliases. Only visible aliases will be displayed
in the completions.

Closes #714
2016-10-30 19:18:13 -04:00
Kevin K
6c11ccf443 fix(debug): fixes the debug feature (#716) 2016-10-29 11:10:14 -04:00
Wim Looman
9cb6facf50 fix: Derive display order after propagation
Don't attempt to change the display order of flags/options until any app
settings have been propagated down from a parent App in case DeriveDisplayOrder
and/or UnifiedHelpMessage are propagated.

Fixes #706
2016-10-26 20:47:24 +02:00
Kevin K
780b4a1828
fix(Fish Completions): fixes a bug where single quotes are not escaped
Closes #704
2016-10-25 10:34:46 -04:00
Kevin K
e9efa8ed6f
chore: clippy run 2016-10-24 05:56:32 -04:00
Kevin K
ebddac791f
fix(Help Message): fixes a regression bug where args with multiple(true) threw off alignment
Closes #702
2016-10-24 05:55:48 -04:00
Kevin K
3e36b0bac4
feat(Completions): adds ZSH completion support
ZSH is now supported in the exact same way as BASH and FISH completion scripts.

Closes #699
2016-10-23 19:32:52 -04:00
Kevin K
291bcccd6b
refactor: makes some minor changes to the private API for better ergonomics 2016-10-23 19:32:42 -04:00
Kevin K
ee6e987acd
refactor(Completions): moves completing functions into their own modules 2016-10-23 19:31:24 -04:00
Kevin K
993622364e
tests(AllowNegativeNumber): fixes failing doc test 2016-10-21 09:54:34 -04:00
Kevin K
2d2ec03995
chore: clippy run 2016-10-21 09:52:16 -04:00
Kevin K
7d6f760a91
style: rustfmt run 2016-10-21 09:41:59 -04:00
Kevin K
f056eb9e4e
refactor: moves some code out of the large main function into it's own 2016-10-21 09:41:45 -04:00
Kevin K
ab06454677
feat(AppSettings): adds new setting AllowNegativeNumbers
One can now use `AppSettings::AllowNegativeNumbers` which functions similar to `AllowLeadingHyphen`
with the exception that only unknown numbers are allowed have a preceding hyphen character.

See the documentation for details and examples.

Closes #696
2016-10-21 09:39:17 -04:00
Kevin K
9ed4d4d795
docs(app/settings.rs): moves variants to roughly alphabetical order 2016-10-21 06:59:58 -04:00
Kevin K
03d2b2ac80
tests: updates tests to new version of arg.to_string() 2016-10-20 19:39:21 -04:00
Kevin K
a79d0f132c
tests(app/help.rs): adds some additional debugging code, and standardizes a few calls 2016-10-20 19:39:21 -04:00
Kevin K
468baadb83
fix: fixes a bug that made determining when to auto-wrap long help messages inconsistent
Closes #688
2016-10-20 19:39:21 -04:00
Kevin K
dc906398fb Merge branch 'master' into stabilize_clap_app! 2016-10-18 10:45:36 -04:00
Kevin K
dbe83dfbe7 Merge branch 'master' into fix_werrnings 2016-10-18 10:17:09 -04:00
tormol
cd516006e3 imp: Stabilize clap_app!
It was de-stabilized in 2.0.0 but hasn't been changed since.

This commit also updates docs to reflect that the "unstable" feature does nothing now.
2016-10-16 21:33:52 +02:00
nabijaczleweli
2608540940
imp(with_defaults): Deprecate App::with_defaults()
Following the discussion on #638 a consensus that it can never work
(and was a mistake in the first place) has been reached

Closes #638
2016-10-16 21:22:54 +02:00
tormol
190aef43fd style: Fix new lints in fish_inner() 2016-10-16 13:05:47 +02:00
tormol
84546f5c7a style: fix one allow()ed lint 2016-10-16 13:04:45 +02:00
tormol
816b0d49c4 style: dis-allow() untriggered lints 2016-10-16 13:04:11 +02:00
tormol
4ee85b95d2 docs: Improve documentation around features
* Clap has dependencies even with all features disabled.
* The "nightly" feature does nothing, so don't mention it.
* Explain the difference between "unstable" and "nightly" better.
* Split features into groups (default, opt-in, clap-development).
* For contributors: update what tests should be run, and remove make command.
* Removes a repeated word and splits up some long markdown lines.

Also groups features by category and dependencies by feature in Cargo.toml.
2016-10-16 11:31:12 +02:00
tormol
835f75e3ba fix(features): Make lints not enable other nightly-requiring features 2016-10-16 11:31:12 +02:00
tormol
86828a5024 chore(debug): fix a single typo in a debug message 2016-10-16 11:31:12 +02:00
tormol
3ccde7a4b8 docs: reword docs for ErrorKind and app::Settings
Also adds a blank line between variants and
wraps markdown lines at punctuation when it makes sense. (Doesn't affect generated docs)
2016-10-16 11:31:12 +02:00
tormol
9f6217a424 docs(ErrorKind): improve some errors about subcommands
* InvalidSubcommand requires feature="suggestions".
* UnknownArgument can also be caused by unrecognized subcommands.
2016-10-16 11:31:12 +02:00
tormol
996fc38176 docs: fix tests that fail when the "suggestions" feature is disabled 2016-10-16 11:31:12 +02:00
tormol
da88fd254b style: only ignore clippy warning if lints are enabled
else you get another warning!
2016-10-16 11:31:12 +02:00
tormol
af9e1a393c docs: fix the OsString-using doc-tests 2016-10-16 11:31:12 +02:00
tormol
4c27f0ade9 tests: run OsString-using doc-tests on unix platforms
Closes #506
2016-10-16 11:31:12 +02:00
tormol
8c0f55516f docs(yaml): make sure the doc-tests don't fail before "missing file"
Removing an unused import is the only visible change.
2016-10-16 11:31:12 +02:00
tormol
0ba9f4b123 docs: tag non-rust code blocks as such instead of ignoring them 2016-10-16 11:31:12 +02:00
tormol
330a376a46 tests: run or compile some currently ignored doc-tests 2016-10-16 11:31:12 +02:00
Chiu-Hsiang Hsu
a61eaf8aad fix(Completions): fish completions for nested subcommands 2016-10-15 17:45:58 +08:00
tormol
5778871951 style: remove the .ok() in result.ok().expect("...")
clippy doesn't check doc-tests and `include!()`d files,
so there might bee more un-reported lint.
2016-10-05 23:16:22 +02:00
tormol
7f797e68d8 style: fix lints in code that's not compiled if the opt-out feature "color" is set 2016-10-05 23:16:22 +02:00
tormol
102fb7d2ce style: fix lints in yaml-related functions 2016-10-05 23:16:15 +02:00
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