Commit graph

915 commits

Author SHA1 Message Date
Kevin K
7ad123e2c0 fix: adds a debug assertion to ensure all args added to groups actually exist
Closes #917
2017-05-16 07:23:22 -04:00
Kevin K
cbea3d5acf docs(App::template): adds details about the necessity to use AppSettings::UnifiedHelpMessage when using {unified} tags in the help template
Closes #949
2017-05-16 07:23:22 -04:00
Kevin K
f9b0d65783 docs(Arg::allow_hyphen_values): updates the docs to include warnings for allow_hyphen_values and multiple(true) used together 2017-05-16 07:23:22 -04:00
Kevin K
ab2f4c9e56 fix: fixes a bug where args that allow values to start with a hyphen couldnt contain a double hyphen -- as a value
Closes #960
2017-05-16 07:23:22 -04:00
Kevin K
54c16836de fix: fixes a bug where positional argument help text is misaligned 2017-05-10 20:29:54 -04:00
Kevin K
9f9364b1d8 fix: fixes a bug where args with last(true) and required(true) set were not being printed in the usage string
Closes #944
2017-05-07 10:46:03 -04:00
Kevin K
8713da2372 fix: fixes a bug that was printing the arg name, instead of value name when Arg::last(true) was used
Closes #940
2017-05-07 10:46:03 -04:00
Kevin K
fedb46b5b1 fix: fixes a bug where flags were parsed as flags AND positional values when specific combinations of settings were used
This commit fixes a bug where using `AppSettings::AllowHyphenValues`
would cause flags with longs be *also* parsed as positional values.

Closes #946
2017-05-07 10:46:03 -04:00
Kevin K
52d110df81 docs(AllowHyphenValues): updates the docs to remove old limitations that no longer apply 2017-05-07 10:46:03 -04:00
Nuew
d5ef895541
api(Arg): add default_value_os
Also add related tests, and reframe `default_value` in terms of
`defualt_value_os`.
2017-04-24 15:49:59 -04:00
Pyry Kontio
0a4384e350 api(arg_matches.rs): Added a Default implementation for Values and OsValues iterators. 2017-04-23 23:49:20 +09:00
Kevin K
85b0e1cc4b
imp(PowerShell Completions): massively dedups subcommand names in the generate script to make smaller scripts that are still functionally equiv 2017-04-18 23:17:05 -04:00
Kevin K
a8bce55837
fix(PowerShell Completions): fixes a bug where powershells completions cant be used if no subcommands are defined
Closes #931
2017-04-18 23:01:20 -04:00
Michael Daffin
71dabba3ea docs: Fix a typo the minimum rust version required 2017-04-07 10:02:00 +01:00
Kevin K
6aa4ba8114 fix: fixes a missing newline character in the autogenerated help and version messages in some instances 2017-04-05 10:59:55 -04:00
Kevin K
f7a8877978 feat(clap_app!): adds support for arg names with hyphens similar to longs with hyphens
One can now use `("config-file")` style arg names

Closes #869
2017-04-05 00:57:47 -04:00
Kevin K
bc08ef3e18 docs(clap_app!): documents the --("some-arg") method for using args with hyphens inside them
Closes #919
2017-04-05 00:47:19 -04:00
Kevin K
59272b06cc feat: allows distinguishing between short and long version messages (-V/short or --version/long)
One can now use `App::long_version` to dsiplay a different (presumably
longer) message when `--version` is called. This commit also adds the
corresponding print/write long version methods of `App`
2017-04-05 00:42:43 -04:00
Kevin K
d82b4be5d7 api: adds new App method calls for printing and writing the long version of help messages
One can now use `App::print_long_help` or `App::write_long_help`

Note that `App::write_long_help` is **NOT** affected by kbknapp/clap-rs#808 in the manner
that `App::write_help` help is and thus should be preferred if at all possible.
2017-04-05 00:42:43 -04:00
Kevin K
6b371891a1 feat: allows distinguishing between short and long help with subcommands in the same manner as args
One can use `App::about` for `-h` short help messsages or
`App::long_about` for `--help` long help messages.
2017-04-05 00:42:43 -04:00
Kevin K
ef1b24c3a0 feat: allows specifying a short help vs a long help (i.e. varying levels of detail depending on if -h or --help was used)
One can now use `Arg::long_help` which will be displayed when the user
runs `--help`. This is typically longer form content and will be
displayed using the NextLineHelp methodology.

If one specifies the standard `Arg::help` it will be displayed when the
user runs `-h` (by default, unless the help short has been overridden).
The help text will be displayed in the typical clap fashion.

The help format requested (-h/short or --help/long) will be the
*default* displayed. Meaning, if one runs `--help` (long) but only an
`Arg::help` has been provided, the message from `Arg::help` will be
used. Likewise, if one requests `-h` (short) but only
`Arg::long_help` was provided, `Arg::long_help` will be displayed appropriately
wrapped and aligned.

Completion script generation *only* uses `Arg::help` in order to be
concise.

cc @BurntSushi thanks for the idea!
2017-04-05 00:42:43 -04:00
Kevin K
8b2ceb8368 fix: fixes a bug that wasn't allowing help and version to be properly overridden
One should be able to override the auto generated help and version flags
by simply providing an arg with a long of `help` or `version`
respectively. This bug was preventing that from happening.

However, now that it's fixed if one was relying on adding an arg with a
long of `help` or `version` and using `get_matches_safe` to produce the
`ErrorKind::HelpDisplayed` or `ErrorKind::VersionDisplayed` errors they
**WILL NOT** happen anymore.

This is because the bug was causing those "errors" to occur (i.e. the
help or version message to be displayed). The "fix" to get that
functionality back is to either:

 * Remove the arg with the long of `help` or `version`
 * Use `ArgMatches::is_present` instead of `App::get_matches_safe` to check for the presence of your custom help or version flag

Option 1 is the easiest provided one wasn't using said arg to *also*
override other aspects of the flags as well (short, help message, etc.)

Even though this may break some code, as per the compatibility policy
listed in the readme; code that breaks due to relying on a bug does
*not* constitute a major version bump. I will however be bumping the
minor version instead of just the patch version. I will also be
searching for, contacting, and attempting to submit PRs to any affected
projects prior to releasing the next version to crates.io

Closes #922
2017-04-04 19:59:03 -04:00
Kevin K
f93cadd74b tests: fixes a missing import for a doctest and uses conditional doc-testing 2017-03-30 15:19:17 -04:00
Kevin K
0e4fd96d74 fix(Custom Usage Strings): fixes the usage string regression when using help templates 2017-03-30 13:30:23 -04:00
Kevin K
a442211b39 fix(usage): fixes a big regression with custom usage strings 2017-03-24 11:27:23 -04:00
Richard Janis Goldschmidt
d49e8292b0
api(App::name): adds the ability to change the name of the App instance after creation
Closes #908
2017-03-22 20:27:20 -04:00
CrazyMerlyn
89e6ea861e
api(Arg::hide_default_value): adds ability to hide the default value of an argument from the help string
Adds a new method, `Arg::hide_default_value`, which allows for
specifying whether the default value of the argument should be hidden
from the help string.

Closes #902
2017-03-22 20:26:31 -04:00
CrazyMerlyn
6bf5bf5bee
fix(yaml): adds support for loading author info from yaml
fix(yaml): adds support for loading author info from yaml
2017-03-22 20:23:55 -04:00
Pierre-Eric Pelloux-Prayer
f8f68cf825 imp: add fish subcommand help support 2017-03-17 17:46:24 +01:00
Kevin K
c8eb0384d3
imp: options that use require_equals(true) now display the equals sign in help messages, usage strings, and errors"
Closes #903
2017-03-16 21:43:36 -04:00
Armin Ronacher
e06689fc26 Propagate terminal widths to subcommands 2017-03-16 14:19:10 +01:00
Kevin K
74b751ff2e
fix(ArgRequiredElseHelp): fixes the precedence of this error to prioritize over other error messages
Closes #895
2017-03-12 12:52:09 -04:00
Kevin K
9a3bc98e9b
fix(Positionals): fixes some regression bugs resulting from old asserts in debug mode.
Closes #896
2017-03-12 12:43:10 -04:00
Kevin K
96884aa1b2
refactor: implements PartialEq for some of the base structs 2017-03-11 12:38:24 -05:00
Kevin K
f9668297a4
api(Arg::last): adds the ability to mark a positional argument as 'last' which means it should be used with -- syntax and can be accessed early
Marking a positional argument `.last(true)` will allow accessing this argument earlier if the `--` syntax is used (i.e. skipping other positional args)
and also change the usage string to one of the following:

* `$ prog [arg1] [-- <last_arg>]`
* `$ prog [arg1] -- <last_arg>` (if the arg marked `.last(true)` is also marked `.required(true)`)

Closes #888
2017-03-11 12:14:54 -05:00
Kevin K
989862d2cb
chore: fixes small rebase regression 2017-03-10 15:27:24 -05:00
Kevin K
9d4535e1c3
chore: clippy run 2017-03-10 08:24:30 -05:00
Kevin K
075036c28d
fix: fixes a regression 1.11.0 feature 2017-03-10 08:24:30 -05:00
Kevin K
1e4cce0291
tests: corrects the debug messages from the usage module 2017-03-10 08:24:30 -05:00
Kevin K
d2b4c2c61b
fix: fixes false positive clean parse when the suggestions feature is disabled and InferSubcommands is enabled 2017-03-10 08:24:30 -05:00
Kevin K
b841f3743f
fix: fixes a failing build with no-default-features 2017-03-10 08:24:30 -05:00
Kevin K
d484da0d28
fix: fixes a misspelled import for Windows 2017-03-10 08:24:29 -05:00
Kevin K
33eb5a6db0
tests: fixes failing dual usage string help test 2017-03-10 08:24:29 -05:00
Kevin K
622b609c57
refactor: moves usage string generation code into it's own module 2017-03-10 08:24:29 -05:00
Kevin K
44ed8b663c
refactor: moves validation code into it's own module 2017-03-10 08:24:29 -05:00
Kevin K
c8ab24bafa
imp: when AppSettings::SubcommandsNegateReqs and ArgsNegateSubcommands are used, a new more accurate double line usage string is shown
Closes #871
2017-03-10 08:24:29 -05:00
Kevin K
d63d404e5e
fix: doesn't print the argument sections in the help message if all args in that section are hidden 2017-03-10 08:24:28 -05:00
Kevin K
539ad6073f
fix: doesn't include the various [ARGS] [FLAGS] or [OPTIONS] if the only ones available are hidden
Closes #882
2017-03-10 08:24:28 -05:00
Kevin K
97e8db23b3
fix: now correctly shows subcommand as required in the usage string when AppSettings::SubcommandRequiredElseHelp is used
Close #883
2017-03-10 08:24:28 -05:00
Kevin K
91d8280322
chore: rustfmt run 2017-03-10 08:24:28 -05:00
Kevin K
6f638a53c1
perf: doesn't run arg_post_processing on multiple values anymore 2017-03-10 08:24:28 -05:00
Kevin K
150756b989
setting(InferSubcommands): adds a setting to allow one to infer shortened subcommands or aliases (i.e. for subcommmand "test", "t", "te", or "tes" would be allowed assuming no other ambiguities)
Closes #863
2017-03-10 08:22:31 -05:00
Joost Yervante Damad
8adf353e0b
fix(help): don't show ARGS when there are only hidden positional args
Also no need to check for Hidden inside for that already is filtered
on !Hidden.

Closes #882
2017-03-10 08:22:31 -05:00
Kevin K
24e3839220
perf: changes internal use of VecMap to Vec for matched values of Args
This makes a very big difference for CLIs that parse a large number of
values (think ripgrep over a large directory).

This commit improved the ripgrep parsing of ~2,000 values, simulating
giving ripgrep a bunch of files. Parsing when from ~1,200,000 ns to
~400,000 ns! This was conducted a i7-5600U 2.6GHz
2017-03-10 08:22:31 -05:00
Caleb Jones
c5dac3fa43 Support loading help_message and version_message from the YAML 2017-03-10 01:54:50 -05:00
Caleb Jones
389c413b70 Allow customizing the --version and --help messages 2017-03-10 01:01:56 -05:00
Anthony Ramine
f4939ad560 Remove direct dependency on libc
It's not actually used anymore anywhere.
2017-03-05 19:44:16 +01:00
Kevin K
8da0303bc0
perf: vastly reduces the amount of cloning when adding non-global args minus when they're added from App::args which is forced to clone 2017-02-28 08:30:14 -05:00
Kevin K
0a922e5f61
tests: adds parsing cases to ripgrep bench 2017-02-28 08:30:14 -05:00
Kevin K
0efa411963
perf: refactor to remove unneeded vectors and allocations and checks for significant performance increases
Building an `App` struct with a fair number of args/flags/switches, etc. (used ripgrep as test case)
went from taking ~21,000 ns to ~13,000ns.
2017-02-28 08:30:13 -05:00
Kevin K
b55cae5fdb
refactor: removes unused fields and moves some bools to bitfields 2017-02-28 08:30:09 -05:00
Corey Farwell
5ee2665e7a Implement ExactSizeIterator for Values. (#877) 2017-02-26 23:20:52 -05:00
Kevin K
6bf94606c2
test: fixes failing doc test 2017-02-22 20:37:56 -05:00
Marco A L Barbosa
fa26d40a18 Fix missing line before code block 2017-02-22 11:25:10 -03:00
Kevin K
588f373ea8
chore: rustfmt run 2017-02-20 21:16:14 -05:00
Kevin K
8c2dd28718
fix: fixes some memory leaks when an error is detected and clap exits 2017-02-20 21:16:07 -05:00
Kevin K
6b5725836f Merge branch 'master' into issues-833,849 2017-02-20 20:36:15 -05:00
Kevin K
1ae2110801
fix: fixes a trait that's marked private accidentlly, but should be crate internal public 2017-02-20 20:31:57 -05:00
Kevin K
10ca4d1e21
chore: rustfmt run 2017-02-20 20:24:28 -05:00
Kevin K
f002693dec
feat(Options): adds the ability to require the equals syntax with options --opt=val
Closes #833
2017-02-20 20:24:27 -05:00
Kevin K
e0f7722685
style: improves the style of doc tests and examples to increase readability and uniformity 2017-02-20 20:24:27 -05:00
Kevin K
0f2a378219
api: provides default_value_os and default_value_if[s]_os
One can now define default values that contain invalid UTF-8.

The underlying implementation has also been changed to use OsStrs in order to avoid duplication
of code and provide the new APIs basically for free.

Closes #849
2017-02-20 20:24:24 -05:00
Kevin K
fb7057cc7a
refactor(Arg): removes duplicate and uses Base, Switched, and Valued internally now 2017-02-20 19:06:36 -05:00
Kevin K
65b12f9107
chore: clippy run 2017-02-20 19:06:36 -05:00
Niklas Claesson
1971209c0c Fix minor documentation bug 2017-02-20 23:13:06 +01:00
Peter Williams
68e03681d8 refactor: use the atty crate for isatty() detection
Not only does this remove some unsafe code from clap itself, `atty` does the
right thing on Windows too. This isn't relevant now since we don't currently
support colorized output on Windows, but will come in handy if/when we
implement that feature (#836).
2017-02-19 11:12:55 -05:00
Eduard-Mihai Burtescu
f28b2353b2 Add missing fragment specifier to a clap_app! rule. 2017-02-18 12:03:41 +02:00
Peter Williams
e635658dad tests: fix clap_app! doctest 2017-02-16 10:48:34 -07:00
Kevin K
e3296e566b Docs (#854)
* docs(App::template) adds missing categories and fixes descriptions

* docs(clap_app): documents all the shorthand syntax

Closes #736

* chore: fixes crates.io category...hopefully
2017-02-16 09:44:44 -05:00
Kevin K
5e9b9cf4dd
fix(Completions): fixes a bug that tried to propogate global args multiple times when generating multiple completion scripts
Closes #846
2017-02-15 11:01:41 -05:00
Kevin K
92919f5f67 Call this PR "Raid" cause it's squashin bugs! (#843)
* tests: adds tests for default values triggering conditional requirements

* fix: fixes a bug where default values should have triggered a conditional requirement but didnt

Closes #831

* tests: adds tests for missing conditional requirements in usage string of errors

* fix: fixes a bug where conditionally required args werent appearing in errors

* tests: adds tests for completion generators

* tests: adds tests for completions with binaries names that have underscores

* fix: fixes a bug where ZSH completions would panic if the binary name had an underscore in it

Closes #581

* fix: fixes bash completions for commands that have an underscore in the name

Closes #581

* chore: fix the category for crates.io

* docs(Macros): adds a warning about changing values in Cargo.toml not triggering a rebuild automatically

Closes #838

* fix(Completions): fixes a bug where global args weren't included in the generated completion scripts

Closes #841

* fix: fixes a println->debugln typo

* chore: increase version
2017-02-03 17:43:49 -05:00
Kevin K
07d985d8c5 Issues 839,840 (#842)
* fix: fixes a critical bug where subcommand settings were being propogated too far

Closes #832

* imp: adds ArgGroup::multiple to the supported YAML fields for building ArgGroups from YAML

Closes #840

* chore: increase version
2017-02-03 15:46:25 -05:00
Martin Geisler
564c5f0f17 fix: allow final word to be wrapped in wrap_help
Before, inserting a newline did not move the prev_space index forward.
This meant that the next word was measured incorrectly since the
length was measured back to the word before the newly inserted
linebreak.

Fixes #828.
2017-01-30 18:33:48 +01:00
Martin Geisler
84d8c5476d fix: actually show character in debug output
The &help[j..j] string slice was empty so nothing was shown.
2017-01-30 18:33:48 +01:00
Martin Geisler
aff4ba18da fix: include final character in line lenght
Before, wrapping the help text at, say, 80 characters really meant
that every line could be at most 79 characters wide.

Lines can now be up to and including avail_chars columns wide.

If needed, a desired margin or padding can be subtracted from the
avail_chars argument at a later point.
2017-01-30 18:33:48 +01:00
Kevin K
69bd16c410
chore: clippy run 2017-01-29 21:19:00 -05:00
Richard Janis Goldschmidt (Beckert)
f9f778e8a4 Fix finding required arguments in group arguments (#829)
This fixes #827. The problem was that the check `grp.args.contains(&grp.args[i])` was a) trivially fulfilled (of course `grp.args[i]` is contained in `grp.args`) and b) causing an out-of-bounds error, since the indices were taken from `.required.len()`.

With this change the argument in the group will be removed from the list of required arguments, as intended.
2017-01-29 18:14:04 -08:00
Trevor Spiteri
5b29be9b07 docs: fix link from app_from_crate! to crate_authors! (#822) 2017-01-29 18:13:34 -08:00
Richard Janis Goldschmidt (Beckert)
ed52851c5d Fix confusing, wrong wording in doc (#821) 2017-01-29 18:12:54 -08:00
Richard Janis Goldschmidt
f1b11886dc Explain how AppSettings::ArgRequiredElseHelp and Arg::default_value interact
When calling the executable without arguments one expects a help message. However, if even one argument has a default value, the validation step of the parser will always see at least one argument, and therefore report success. This effectively disables the settings.
2017-01-18 17:14:06 +01:00
pixelistik
5de1b6e1c8 doc: Fix typo 2017-01-08 23:45:03 +01:00
Brian Bowman
4f30a65b9c docs: fix spelling of "guaranteed" 2017-01-07 20:18:59 -06:00
Kevin K
9d88f19181
refactor: 'reverts' a breaking change until further discussion and approval has taken place 2017-01-05 19:26:16 -05:00
Kevin K
6edde30b8e
setting(AllowMissingPositional): allows one to implement $ prog [optional] <required>
Closes #636
2017-01-04 00:02:26 -05:00
Kevin K
985536c8eb
setting(PropagateGlobalValuesDown): adds a setting to allow automatically propagating global args values down through *used* subcommands
Closes #694
2017-01-02 23:05:50 -05:00
Kevin K
20842ed8c2
fix: fixes an issue where the full help message wasn't written when doing App::write_help
Closes #801
2017-01-02 23:05:50 -05:00
Kevin K
ad4691b71a
feat(Help Wrapping): long app names (with spaces), authors, and descriptions are now wrapped appropriately
Closes #777
2017-01-02 16:43:45 -05:00
Kevin K
1f33de5450
imp(Default Values): improves the error message when default values are involved
Closes #774
2017-01-02 16:43:07 -05:00
Kevin K
26c670ca16
fix(Low Index Multiples): fixes a bug which caused combinations of LowIndexMultiples and allow_hyphen_values to fail parsing 2017-01-02 14:33:56 -05:00
Kevin K
baff4200a4
refactor: implements BitOr for AppFlags to improve some ergonomics and performance 2017-01-02 12:23:03 -05:00