Commit graph

2427 commits

Author SHA1 Message Date
Alex Burka
f61ce3f55f fix: ignore PropagateGlobalValuesDown deprecation warning
Fixes #1086.
2017-10-27 12:54:03 -04:00
Kevin K
fc4bd87853 Merge pull request #1084 from kbknapp/issue-1083
Issue 1083
2017-10-26 11:05:17 -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
554083ffc5 Merge pull request #1081 from kbknapp/kbknapp-patch-1
Fix typo in minimum required Rust version
2017-10-24 21:51:35 -04:00
Kevin K
bbd0589c19 Fix typo in minimum required Rust version 2017-10-24 21:51:21 -04:00
Kevin K
794ac237de Merge pull request #1080 from kbknapp/kbknapp-patch-1
chore: fix copy paste typo
2017-10-24 21:50:32 -04:00
Kevin K
385596f6f6 chore: fix copy paste typo 2017-10-24 21:50:19 -04:00
Kevin K
fe814b88e3 Merge pull request #1079 from kbknapp/issues-1031,1050,1056,1066,1071
Issues 1031,1050,1056,1066,1071
2017-10-24 21:49:18 -04:00
Kevin K
3a471b72ce
docs: fixes some typo mistakes 2017-10-24 20:30:11 -04:00
Kevin K
e3eaf56b36
chore: increase version 2017-10-24 15:31:33 -07:00
Kevin K
2558083fe9
tests: adds tests to guard against allowing invalid args accidentally 2017-10-24 15:21:52 -07: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
9435b2a589
tests: adds tests to make sure args are preferred over matching subcommands when values are possible 2017-10-24 14:59:31 -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
b399ee2604
tests: adds tests to ensure number_of_values and default_value can be used together 2017-10-24 12:57:04 -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
f7a6955238
tests: adds tests to make sure args with default values can have conflicts 2017-10-24 12:23:29 -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
9cb92c17c5 Merge pull request #1077 from kbknapp/issue-1076
Issue 1076
2017-10-24 14:59:18 -04:00
Kevin K
2c3f7f6054
tests: adds tests to protect against panics when using globals and calling App::get_matches_from_safe_borrow multiple times 2017-10-24 10:46:00 -04: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
6ac846d850 Merge pull request #1075 from kbknapp/issues-978,1010,1061
Issues 978,1010,1061
2017-10-24 08:01:30 -04:00
Kevin K
48e0529bcd
chore: clippy run 2017-10-23 23:03:40 -04:00
Kevin K
8fd59e0b7b
tests: updates tests new global values being propagated up and down 2017-10-23 22:14:16 -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
cbd09c7fec
tests: refactors the tests for propagating global values and flags as well as adds some tests for default values and flags 2017-10-23 21:27:29 -04:00
Kevin K
0d6cd6e7d9
chore: fixes some spelling mistakes 2017-10-23 21:26:45 -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
Kevin K
8a2e1dbdcd
wip: implement 1061 2017-10-21 15:55:31 -04:00
Kevin K
569ced1f3d Merge pull request #1070 from willmurphyscode/propagate-values-down
Fix 978: global args' values available to all subcommands
2017-10-18 10:40:01 -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
15437bf3a7 use global setting in test 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
Will Murphy
3bedc69bff explanatory test comments 2017-10-18 07:42:17 -04:00
Will Murphy
1948de9c6b remove outdated comment 2017-10-18 07:42:17 -04:00
Will Murphy
a22e20191b rename inner sub command 2017-10-18 07:42:17 -04:00
Will Murphy
6c014f31b3 remove old copy paste test code 2017-10-18 07:42:17 -04:00