Commit graph

1076 commits

Author SHA1 Message Date
etopiei
5220122f72
Adjusted error message, as specified in Issue #1160 2018-02-12 14:39:51 -05:00
Kevin K
7c23bee6b8
setting(AllArgsOverrideSelf): adds a convenience setting to say all args override themselves 2018-02-10 15:42:44 -05:00
Kevin K
db237f3ed2
docs(Self Overrides): adds docs to better explain overrides_with 2018-02-09 23:34:58 -05:00
Kevin K
4204787e0f
imp(Self Overrides): allows args to override themselves properly 2018-02-09 23:34:36 -05:00
Kevin K
300a059f51
chore: updates the version tests 2018-02-03 15:22:56 -05:00
Kevin K
cf3eaaeb0c
tests: fixes some typos that caused failing doc tests 2018-02-03 15:14:34 -05:00
Kevin K
41436d3b7d
docs(Arg.rs): updates documentation for the deprecations 2018-02-03 15:06:56 -05:00
Kevin K
6fc70d825c
depr(Arg.rs): adds deprecations in prep for v3
A full list of deprecations is:

* Arg::last -> ArgSettings::Last
* Arg::required -> ArgSettings::Required
* Arg::require_equals -> ArgSettings::RequireEquals
* Arg::allow_hyphen_values -> ArgSettings::AllowHyphenValues
* Arg::takes_value -> ArgSettings::TakesValue
* Arg::hide_possible_values -> ArgSettings::HidePossibleValues
* Arg::hide_default_value -> ArgSettings::HideDefaultValue
* Arg::multiple -> ArgSettings::Multiple (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleValues (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleOccurrences (see Arg::multiple split)
* Arg::global -> ArgSettings::Global
* Arg::empty_values -> ArgSettings::AllowEmptyValues
* Arg::hidden -> ArgSettings::Hidden
* Arg::case_insensitive -> ArgSettings::IgnoreCase
* Arg::use_delimiter -> ArgSettings::UseDelimiter
* Arg::require_delimiter -> ArgSettings::RequireDelimiter
* Arg::hide_env_values -> ArgSettings::HideEnvValues
* Arg::next_line_help -> ArgSettings::NextLineHelp
* Arg::set -> Arg::unset_setting (consistent naming with App)
* Arg::unset -> Arg::setting (consistent naming with App)

Relates to #1037
2018-02-03 15:00:55 -05:00
Kevin K
04b7532bcb
docs(App.rs): updates the docs away from deprecated methods 2018-01-30 21:10:35 -05:00
Kevin K
c441467de3
depr(App.rs): deprecates old App methods in prep for v3
A full list of deprecations is:

* App::version_message -> App::mut_arg
* App::version_short -> App::mut_arg
* App::help_message -> App::mut_arg
* App::help_short -> App::mut_arg
* App::from_yaml -> serde
* App::usage -> App::override_usage (+no longer assumes leading \t)
* App::help -> App::override_help
* App::template -> App::help_template
* App::args_from_usage -> App::args(&str)
* App::arg_from_usage -> App::arg(Arg::from)
* App::write_help -> &self -> &mut self (#808)
* App::gen_completions -> clap_completions::generate
* App::gen_completions_to -> clap_completions::generate_to
* App::get_matches_safe -> App::try_get_matches (#950 Lib Blitz naming
consistency)
* App::get_matches_from_safe -> App::try_get_matches_from (#950 Lib Blitz
naming consistency)
* App::get_matches_safe_borrow -> App::try_get_matches_from_mut (#950 Lib
Blitz naming consistency)
2018-01-30 21:04:19 -05:00
Kevin K
1fa4afa45d
tests: continues to update tests to take advantage of new internals 2018-01-25 22:54:05 -05:00
Kevin K
7788ef70d9
wip: continuing to iron out the bugs from the internal refactor 2018-01-25 22:36:20 -05:00
Kevin K
7673dfc085
perf: refactors the POSIX override handling to lazy handling
This commit primarily changes to a lazy handling of POSIX overrides by
relying on github.com/bluss/ordermap instead of the old HashMap impl.
The ordermap allows us to keep track of which arguments arrived first,
and therefore determine which ones should be removed when an override
conflict is found.

This has the added benefit of we no longer have to do the bookkeeping to
keep track and override args as they come in, we can do it once at the
end.

Finally, ordermap allows fast Vec like iteration of the keys, which we
end up doing several times. Benching is still TBD once the v3 prep is
done, but this change should have a meaningful impact.
2018-01-25 15:08:57 -05:00
Kevin K
e890b647f3
wip: still setting the stage for v3 2018-01-25 12:29:36 -05:00
Kevin K
1ab10275e4
style: rustfmt run 2018-01-25 12:21:17 -05:00
Kevin K
6705195449
wip: setting the stage for serde, custom derive, and v3 2018-01-25 12:20:04 -05:00
Kevin K
4f3231a51c fix(Help): fixes an issue where help is not properly written using App::write_help
Contains a *MINOR* breaking change. App::write_help now requires `&mut self` instead of `&self`.

This fixes a major bug where the help message is entirely incorrect.
More can be found at https://github.com/kbknapp/clap-rs/issues/808

I've decided to make this change because it was preventing further progress.

Anyone's code who breaks the fix is trivial:

```rust
// OLD BROKEN
let app = App::new("broken");
let mut out = io::stdout();
app.write_help(&mut out).expect("failed to write to stdout");

// NEW FIX
let mut app = App::new("broken");  // <-- let mut
let mut out = io::stdout();
app.write_help(&mut out).expect("failed to write to stdout");
```

Closes #808
2018-01-24 11:34:14 -05:00
Kevin K
acdbd47152 wip: changes to builders in prep for v3 2018-01-24 11:34:14 -05:00
Kevin K
d03d13399f
Merge branch 'master' into issue-1135 2018-01-20 15:27:58 -05:00
Will Murphy
4896e817be clean up comments 2018-01-18 20:45:31 -05:00
Will Murphy
74976a0df9 Implement required_unless for flag
Flags were incorrectly reporting that they never had required_unless args.
2018-01-18 20:34:22 -05:00
Will Murphy
c6c9d9b33f Merge branch 'master' into issue-1135 2018-01-18 20:32:44 -05:00
Kevin K
6e66eac2ff
Merge branch 'master' into patch-1 2018-01-18 15:07:17 -05:00
Kevin K
5bb926ebf9 chore: fix html_doc_root 2018-01-18 15:06:23 -05:00
discosultan
61cf3f9142 Fix typo in arg.rs 2018-01-18 15:46:20 +01:00
Segev Finer
25561decf1 feat(completions/zsh.rs): Escape possible values for options 2018-01-16 01:55:48 +02:00
Segev Finer
2cbbfa8ce9 style(completions/zsh.rs): Cleanup documentation and naming 2018-01-16 01:52:44 +02:00
Segev Finer
f3b0afd2be feat(completions/zsh.rs): Implement postional argument possible values completion 2018-01-16 01:52:44 +02:00
Segev Finer
a652260795 fix(completions/zsh.rs): Add missing autoload for is-at-least 2018-01-15 20:41:08 +02:00
Kevin K
e077e0c930
Merge branch 'master' into zsh-completion-improvements 2018-01-15 11:53:25 -05:00
Kevin K
a46ff132f1
Merge branch 'master' into patch-1 2018-01-15 11:52:21 -05:00
Segev Finer
16b4f143ff fix(completions/zsh.rs): Don't pass -S to _arguments if Zsh is too old
If you do pass it than _arguments considers -C as a possible option in
the completions.
2018-01-14 07:13:27 +02:00
Segev Finer
1146f0da15 fix(completions/zsh.rs): Maybe fix completions with mixed positionals and subcommands
Optional positionals mixed with subcommands will still break this, since
I can't see how to tell which element of $line is the command than.
Mixing optional positionals with subcommands is a bit weird and awkward
though...
2018-01-14 07:13:23 +02:00
Segev Finer
e39aeab848 feat(completions/zsh.rs): Complete positional arguments properly
This changes the way we complete positionals to complete them using
_arguments, as should be done, instead of completing their uppercase name
as a string.

Currently I made it offer _files completion for all positional arguments.
This can be improved to complete actual possible values of the arguments
and only complete files if the argument truly takes them. But this will
require further changes in clap to actually have the required
functionality to get this information.
2018-01-14 07:12:14 +02:00
Will Murphy
dc0d8ba89c note-to-self comments 2018-01-13 16:32:45 -05:00
Matt Kraai
b83f387b80
Fix typo 2018-01-10 21:01:21 -08:00
Segev Finer
0e185b922e fix(completions/zsh.zsh): Remove redundant code from output
Fixes #1142
2018-01-10 20:29:01 +02:00
Kevin K
3e97085e58 chore: udpates html doc root 2018-01-09 12:02:35 -05:00
Kevin K
eb8d919e6f perf: further debloating by removing generics from error cases 2018-01-09 10:53:20 -05:00
Kevin K
7ac5a5af9f tests: cleans up certain test cases litle by little 2018-01-09 10:53:20 -05:00
Kevin K
03e413d717 perf: debloats clap by deduplicating logic and refactors
This commit removes heavy use of macros in certain functions which
drastically increased code size. Some of the macros could be turned
into functions, while others could be removed entirely.

Examples were removing arg_post_processing! which did things like
checked overrides, requirements, groups, etc. This would happen
after every argument was parsed. This macro also had several other
macros inside it, and would expand to several tens or hundreds of
lines of code.

Then add that due to borrowck and branch issues, this macro may be
included in multiple parts of a function. Unlike traditional functions
each of these uses expanded into TONS of code (just like agressive
inlining).

This commit primarily removes those arg_post_processing! calls and
breaks up the functionality into two types. The first must happen at
ever new argument (not new value, but new argument). This is pretty
cheap. The next type was moved to the end of parsing validation section
which is more expensive, but only happens once.

i.e. clap was validating each argument/value as it saw them, now it's
lazy and validates them all at once at the end. This MUCH more
efficient!
2018-01-09 10:53:20 -05:00
Kevin K
eac4ca7898
Merge branch 'master' into zsh-long-options-completion-fix 2018-01-09 10:50:40 -05:00
Kevin K
a23135a46a
Merge branch 'master' into fixDocLinks 2018-01-09 10:49:21 -05:00
Segev Finer
46365cf8be fix(completions/zsh.rs): Fix completion of long option values
Long options take their argument either in the next word or after an
equals sign, but the Zsh completion specified that they take it either
in the same word with no separator or in the next word. See the
documentation of the Zsh _arguments function for more information.
2018-01-06 14:43:15 +02:00
Cameron Dershem
56e734b839 docs: fixes broken links.
Small correction to add a link to the source in the documentation, previously
it was a placeholder.

`rustdoc` does not appear to package assets with the docs, therefore
relative links looking for static files do not work. The links are
consistent enough on github that the static files can be directly linked
to on the master branch.
2017-12-27 00:00:06 -05:00
Alex Helfet
ba7f1d18eb fix(bash completion): Change the bash completion script code generation to support hyphens. 2017-12-16 12:44:57 +00:00
Eduardo Pinho
dde7fcf1ca Support trailing comma in arg_enum! fields 2017-12-07 00:53:55 +00:00
Kevin K
e962f2cece
chore: increase version 2017-12-02 15:34:02 -05:00
Kevin K
fb41d062ee
api(Arg): adds Arg::hide_env_values(bool) which allows one to hide any current env values and display only the key in help messages 2017-12-02 15:09:21 -05:00
Kevin K
8c0cc5c386
style: rustfmt run 2017-11-28 08:57:04 -05:00
Kevin K
80993357e1
api: Adds Arg::case_insensitive(bool) which allows matching Arg::possible_values without worrying about ASCII case
When used with `Arg::possible_values` it allows the argument value to pass validation even if
the case differs from that of the specified `possible_value`.

```rust
let m = App::new("pv")
    .arg(Arg::with_name("option")
        .long("--option")
        .takes_value(true)
        .possible_value("test123")
        .case_insensitive(true))
    .get_matches_from(vec![
        "pv", "--option", "TeSt123",
    ]);

assert!(m.value_of("option").unwrap().eq_ignore_ascii_case("test123"));
```

This setting also works when multiple values can be defined:

```rust
let m = App::new("pv")
    .arg(Arg::with_name("option")
        .short("-o")
        .long("--option")
        .takes_value(true)
        .possible_value("test123")
        .possible_value("test321")
        .multiple(true)
        .case_insensitive(true))
    .get_matches_from(vec![
        "pv", "--option", "TeSt123", "teST123", "tESt321"
    ]);

let matched_vals = m.values_of("option").unwrap().collect::<Vec<_>>();
assert_eq!(&*matched_vals, &["TeSt123", "teST123", "tESt321"]);
```

Closes #1118
2017-11-28 08:57:04 -05:00
Kevin K
ce6ca492c7
docs: changes the demo version to 2.28 to stay in sync 2017-11-28 04:38:37 -05:00
Kevin K
6f4c341241
api: Adds the traits to be used with the clap-derive crate to be able to use Custom Derive
Currently to use these traits clap must be built with the `unstable` feature. This does not
require a nightly compiler. These traits and APIs may change without warning (hence the `unstable`
feature flag). Once they have been stablelized and the `clap-derive` crate is released the
`unstable` feature flag will no longer be required.
2017-11-27 09:55:52 -05:00
Kevin K
8a26ff07b0
style: changes the display of the env var from 'env:VAR: value' to 'env: VAR=value' 2017-11-27 09:55:43 -05:00
Igor Gnatenko
bfcf5dd076 use .bash as extension for bash completions
* bash-completions have code to use only `foo`, `foo.bash` and `_foo`
files for completion
* /usr is proper place for system-wide stuff rather than /etc

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2017-11-23 18:48:36 +01:00
Kevin K
a283d69fc0
fix: Fixes a regression where --help couldn't be overridden
Closes #1112
2017-11-22 04:11:28 -05:00
Bastien Orivel
a6593410c1 Update bitflags to 1.0 and bump version 2017-11-21 12:39:12 +01:00
Kevin K
2fb758219c fix: fixes a bug that allowed options to pass parsing when no value was provided
Since options have `empty_values(true)` by default, so long as another valid flag
or option came after the option in question, clap would parse it as an empty value
incorrectly. This commit forces the user to explicitly add an empty value.

`--option "" --flag` is allowed
`--option --flag` is no longer allowed unless the user has *also* set `min_values(0)`

This commit also fixes an issue where `-o=` would be parsed as a value of `Some("=")`
instead of `Some("")`.

Closes #1105
2017-11-13 17:02:52 -05:00
Kevin K
46c1317203 chore: silences unused macro warning for debug macros 2017-11-13 17:01:09 -05:00
Kevin K
3f1d23934d chore: fixes the attribute to allow unused imports on nightly
Closes #1095
2017-11-12 12:51:14 -05:00
Johannes Frankenau
002b07fc98 docs: fix typo 2017-11-09 08:56:45 +01:00
Kevin K
e78bb757a3 imp: adds '[SUBCOMMAND]' to usage strings with only AppSettings::AllowExternalSubcommands is used with no other subcommands
Closes #1093
2017-11-06 20:15:07 -05:00
Kevin K
fb08bb5dd5 refactor: removes unused imports on nightly via cfg directive
If one is using a nightly Rust compiler they should compile clap
with the `nightly` feature.

```toml
[dependencies]
clap = { version = "2.27", features = ["nightly"] }
```

This isn't required for compilation to succeed, only to take
advantage of any nightly features used by clap.

If one is compiling with `#[deny(warnings)]` this commit will cause
compilation to fail if one *does not* compile with the `nightly`
since `std::ascii::AsciiExt` is no longer required in in multiple
files as of the latest Rust nightly (Nov 6th, 2017).

Closes #1095
2017-11-06 20:11:19 -05:00
Alex Burka
f61ce3f55f fix: ignore PropagateGlobalValuesDown deprecation warning
Fixes #1086.
2017-10-27 12:54:03 -04:00
Kevin K
67170a8bd7
chore: increase version 2017-10-26 10:09:48 -04:00
Kevin K
0246960bdc
chore: adds term_size as an optional dep 2017-10-26 09:40:21 -04:00
Kevin K
3a471b72ce
docs: fixes some typo mistakes 2017-10-24 20:30:11 -04:00
Kevin K
77ed46841f
fix: fixes a bug where using AppSettings::AllowHyphenValues would allow invalid arguments even when there is no way for them to be valid
Prior to this commit, using `AppSettings::AllowHyphenValues` would allow
ANY argument to pass, even if there was no way it could be valid.

Imagine a CLI with only a single flag (i.e. *no value*) `--flag`, but this setting
is set. The following was valid:

```
$ prog hello
```

This commit fixes that by creating an UnknownArgument error unless the
unknown argument/value in question could legally be parsed as a value
to a valid argument.

Closes #1066
2017-10-24 15:18:56 -07:00
Kevin K
03455b7751
docs: adds addtional blurbs about using multiples with subcommands 2017-10-24 14:59:25 -07:00
Kevin K
0c223f54ed
fix: when an argument requires a value and that value happens to match a subcommand name, its parsed as a value
**This commit contains a breaking change in order to fix a bug.**

The only users affected are those relying on the "bug." The bug is only in code that uses
subcommands, and parent commands with arguments accepting multiple values (positionals or options)
unrestrained *and* where a value may coincide with a subcommand's name.

Imagine a CLI with a positional argument `files` that accepts multiple values but no other conditions
or parameters (just `Arg::multiple(true)`), and a subcommand `log`

Prior to this commit, the following was valid:

```
$ prog file1 file2 file3 log
```

which would be parsed as:

 * files = file1, file2, file3
 * subcommand = log

However, if there was a file named `log` the subcommand isn't callable.

The CLI should be designed in a way that either limits number of values so that clap knows
when `files` is done and can then look for subcommands, or other AppSettings which change
the behavior.

Possible fixes are `Arg::number_of_values`, `Arg::max_values`,
`AppSettings::ArgsNegateSubcommands`, `Arg::require_equals`,
`AppSettings::SubcommandsNegateArgs`, and more.

This *does not* affect CLIs which contain other arguments between the unrestrained multiple
value args, and the any subcommands. Such as if our example above also had a flag `-f`

The following would be parsed the same before and after this commit.

```
$ prog file1 file2 file3 -f log
```

This is because upon reaching the flag `-f`, clap stops parsing `files`.

No other breaking changes were made.

---

When using args with `multiple(true)` on options or positionals (i.e. those args that
accept values) and subcommands, one needs to consider the posibility of an argument value
being the same as a valid subcommand. By default `clap` will parse the argument in question
as a value *only if* a value is possible at that moment. Otherwise it will be parsed as a
subcommand. In effect, this means using `multiple(true)` with no additional parameters and
a possible value that coincides with a subcommand name, the subcommand cannot be called
unless another argument is passed first.

As an example, consider a CLI with an option `--ui-paths=<paths>...` and subcommand `signer`

The following would be parsed as values to `--ui-paths`.

```
$ program --ui-paths path1 path2 signer
```

This is because `--ui-paths` accepts multiple values. `clap` will continue parsing values
until another argument is reached and it knows `--ui-paths` is done.

By adding additional parameters to `--ui-paths` we can solve this issue. Consider adding
`Arg::number_of_values(1)` as discussed above. The following are all valid, and `signer`
is parsed as both a subcommand and a value in the second case.

```
$ program --ui-paths path1 signer
$ program --ui-paths path1 --ui-paths signer signer
```

Closes #1031
2017-10-24 14:59:23 -07:00
Kevin K
5eb342a99d
fix: fixes a bug that prevented number_of_values and default_values to be used together
Closes #1050
Closes #1056
2017-10-24 12:56:02 -07:00
Kevin K
58b5b4be31
fix: fixes a bug that didn't allow args with default values to have conflicts
Closes #1071
2017-10-24 12:22:44 -07:00
Kevin K
d86ec79742
fix: fixes a panic when using global args and calling App::get_matches_from_safe_borrow multiple times
Closes #1076
2017-10-24 10:45:52 -04:00
Kevin K
48e0529bcd
chore: clippy run 2017-10-23 23:03:40 -04:00
Kevin K
a43f9dd4aa
fix: fixes issues and potential regressions with global args values not being propagated properly or at all
Closes #1010
Closes #1061
Closes #978
2017-10-23 21:29:05 -04:00
Kevin K
ead076f03a
docs: updates the docs to reflect changes to global args and that global args values can now be propagated back up the stack 2017-10-23 21:28:26 -04:00
Kevin K
2bb5ddcee6
depr(AppSettings::PropagateGlobalValuesDown): this setting is no longer required to propagate values down or up 2017-10-23 21:25:57 -04:00
Kevin K
899f3d320d
refactor: removes unused imports and fixes spelling error 2017-10-23 20:13:50 -04:00
Will Murphy
ae060c399b more cleanup 2017-10-18 07:42:17 -04:00
Will Murphy
e85079fcff more cleanup 2017-10-18 07:42:17 -04:00
Will Murphy
9c983a5da4 remove accidentally tracked .fmt file 2017-10-18 07:42:17 -04:00
Will Murphy
6158fc9b50 Clean up commented code and old TODOs 2017-10-18 07:42:17 -04:00
Will Murphy
35b21164bc Working implementation 2017-10-18 07:42:17 -04:00
Will Murphy
3916d61f16 compiling recursive implementation 2017-10-18 07:42:17 -04:00
Will Murphy
97b8abe1a7 WORKS but with manual recursion 2017-10-18 07:42:17 -04:00
Will Murphy
fea31ddfb1 WIP something like the right shape 2017-10-18 07:42:17 -04:00
Will Murphy
97e978e7b0 starting path using several small methods, looks promising 2017-10-18 07:42:17 -04:00
Will Murphy
aafcf88354 WIP 2017-10-18 07:42:17 -04:00
Will Murphy
6d981fb970 my tests pass but I broke one existing test 2017-10-18 07:42:17 -04:00
Kevin K
dce616998e
imp: args that have require_delimiter(true) is now reflected in help and usage strings
Closes #1052
2017-10-12 15:11:24 -07:00
Benjamin Fry
85f0fd1c87 always add env parameter when passed 2017-10-11 17:15:48 -07:00
Kevin K
2acd9b23f5
Merge branch 'from_env' of https://github.com/bluejekyll/clap-rs into bluejekyll-from_env 2017-10-07 10:22:23 -07:00
Kevin K
609a1f27a1 Merge pull request #1058 from H2CO3/master
Reduce amount of unsafe code
2017-10-07 12:59:00 -04:00
Árpád Goretity
ac97edde90 Reorganize optionally depending on term_width 2017-10-06 13:14:01 +02:00
Benjamin Fry
2fa8f835de put env: before default as that will be chosen first 2017-10-05 15:09:19 -07:00
Benjamin Fry
81cae1f620 add space in help output 2017-10-05 13:44:25 -07:00
Benjamin Fry
5fccd1fef8 add additional tests 2017-10-05 10:47:53 -07:00
Benjamin Fry
779560b5d5 fix some typos 2017-10-05 10:47:53 -07:00
Benjamin Fry
ec46b55fb3 add documentation and examples 2017-10-05 10:47:53 -07:00
Benjamin Fry
bad5d19edb add env key for help msg 2017-10-05 10:47:53 -07:00