Commit graph

5737 commits

Author SHA1 Message Date
Ed Page
bf86f76306
Merge pull request #3746 from epage/fixes
fix(parser): Increase compatibility between old/new approach
2022-05-24 15:09:19 -05:00
Ed Page
b3847d12f0 docs(ref): Update for _ref derive 2022-05-24 14:53:08 -05:00
Ed Page
33e94df212 docs(example): Update for value_parser 2022-05-24 14:53:08 -05:00
Ed Page
9a913c40e1 fix(help): Show possible values long help 2022-05-24 14:53:08 -05:00
Ed Page
c6a3871544 fix(error): Include PossibleValuesParser values in error 2022-05-24 14:53:08 -05:00
Ed Page
30f2879824 fix: Include value_parser in debug output 2022-05-24 14:53:08 -05:00
Ed Page
a997ee7e10 fix(derive): Improve where errors point 2022-05-24 14:53:08 -05:00
Ed Page
15616bbd13 fix(error): Remove usage from value validation
When to show usage?  We are currently mixed about it.  For `validator`,
we didn't show it at all.  Sometimes we show the used arguments and
sometimes we don't.

With `ValueParser`, I ran into the problem that we weren't showing the
used arguments like we had previously in some cases.  In deciding how to
solve this, I went with the simplest route for now and removed it as the
usage likely doesn't add much context to help people solve their
problem, more so the recommendation for help.  We'll see how the
feedback is on this and adjust.
2022-05-23 20:56:04 -05:00
Ed Page
19dac49fab
Merge pull request #3742 from epage/derive3
feat(derive): Allow users to opt-in to `ValueParser`
2022-05-23 10:33:38 -05:00
Ed Page
e23800e10e doc(derive): Update for value_parser 2022-05-20 20:02:23 -05:00
Ed Page
852a1b15d4 fix(help): Show value_parser's PossibleValues 2022-05-20 19:59:36 -05:00
Ed Page
5b4ea8e56e fix(parser): Print proper upper range bound 2022-05-20 19:48:06 -05:00
Ed Page
2fba6155ec refactor(derive): Separate concerns when removing 2022-05-20 19:27:52 -05:00
Ed Page
a35df14caf feat(derive): Opt-in to inferred value_parser 2022-05-20 19:25:20 -05:00
Ed Page
7845e604e7 perf(derive): Reuse allocations where possible
Only bothered to implement this for `value_parser` cases as `parse`
cases are going to be considered deprecated.
2022-05-20 15:44:19 -05:00
Ed Page
b52c7f115e feat(derive): Allow users to opt-in to ValueParser
For clap 3, its opt-in as a precaution against breaking
compatibility in some weird cases.

This does require the types to implement `Clone`.

Fixes #3734
Fixes #3496
Fixes #3589
2022-05-20 15:38:44 -05:00
Ed Page
b202eed3d5
Merge pull request #3740 from epage/ui
test: Re-enable ui tests
2022-05-20 14:23:57 -05:00
Ed Page
d1d67fd68d
Merge pull request #3739 from epage/bool
fix(parser): Use optimized bool value parser
2022-05-20 14:11:11 -05:00
Ed Page
e0e7383300 test: Re-enable ui tests
`derive_ui.rs` did not have a marker for needing to be updated on MSRV
changes, so it got missed.
2022-05-20 14:10:32 -05:00
Ed Page
5171fce186 fix(parser): Use optimized bool value parser 2022-05-20 12:50:52 -05:00
Ed Page
5de3639666
Merge pull request #3684 from epage/multicall
feat: Stablize multicall
2022-05-20 12:42:53 -05:00
Ed Page
686b0379ce feat(multicall): Stablize multicall
`multicall` allows you to have one binary expose itself as multiple
programs, like busybox does.  This also works well for user clap for
parsing REPLs.

Fixes #2861
2022-05-20 12:20:40 -05:00
Ed Page
1a2b7acd60 test(multicall): Conditionalize suggestion-related case
This impacts the error code (#3676) and the error body and without
suggestions, its redundant.
2022-05-20 12:20:40 -05:00
Ed Page
0628d04174 perf(derive): Reuse allocations for external subcommands
In case the `ArgMatches` is cloned, this forces a constraint that the
underlying type impls `Clone` but that should be safe as we only support
`String` and `OsString`.
2022-05-20 12:02:31 -05:00
Ed Page
d61552a8b8 refactor(derive): Deconstruct arg matches into enums 2022-05-20 11:56:47 -05:00
Ed Page
18f295029f refactor(derive): Consistently handle sub matches 2022-05-20 11:10:26 -05:00
Ed Page
b817c2d2a9 refactor(derive): Separate sub flattening to avoid aliasing 2022-05-20 11:08:05 -05:00
Ed Page
17ec775789
Merge pull request #3736 from epage/edition
fix: Switch to 2021 edition
2022-05-18 10:55:33 -05:00
Ed Page
2abb6804d3 fix: Switch to 2021 edition 2022-05-18 10:35:30 -05:00
Ed Page
d827364ea9 style: Normalize manifests 2022-05-18 10:33:37 -05:00
Ed Page
272334b26a fix: List rust-version for all crates 2022-05-18 10:08:10 -05:00
Ed Page
5806e16dd4 refactor(derive): Don't alias arg matches
Right now, the aliasing is safe (the compiler says so!) but we're going
to be switching to a `&mut` and need to ensure we don't alias.
2022-05-18 09:38:38 -05:00
Ed Page
1446be8a89 feat(derive): Allow destructively constructing from ArgMatches 2022-05-18 09:10:55 -05:00
Ed Page
28ee3d33f7
Merge pull request #3732 from epage/domain
feat(builder): Custom parser for arg values
2022-05-17 19:15:54 -05:00
Ed Page
4a733cd879 fix: Bump MSRV to 1.56.0
This is needed for `Bound::cloned` and fits within official MSRV policy
(2 versions back) and unofficial (6 months, see #3267)
2022-05-17 17:13:08 -05:00
Ed Page
acdf26ac38 style: Make clippy happy 2022-05-17 17:13:08 -05:00
Ed Page
c9e3b81e3c doc(parser): Specify what unwraps are for 2022-05-17 16:58:38 -05:00
Ed Page
91fe9eedc9 feat(parser): Transfer ownership of sub-matches 2022-05-17 16:58:38 -05:00
Ed Page
675ac68f73 fix(parser): Give more flexibility for changes 2022-05-17 16:58:38 -05:00
Ed Page
0033bf60c1 style: Address clippy complaints 2022-05-17 14:11:04 -05:00
Ed Page
63aa236141 feat(parser): Convenient range value parsers
There are several approaches with this
- `value_parser(N..M)`: creates an i64 range
- `value_parser(value_parser!(u16).range(10..))`: creates an u16 range
  that starts at 10
- `RangeI64ValueParser`: create whatever range you want

I was hoping to generalize `RangeI64ValueParser` for any source type,
not just i64, but ran into issues and decided to punt.  I chose `i64` as
the source type as it seemed the most general and didn't run into
portability issues like `isize`.

This is a step towards #3199.  All that is left is for the derive to use
this.
2022-05-17 14:00:52 -05:00
Ed Page
6b0306df9e feat(parsr): Expose all built-in TypedValueParsers
This makes life easier for people, whether they want a geneirc
`NonEmpty<impl TypedValueParser>` or a `PathBufExists(PathBuf)`.
2022-05-16 17:16:42 -05:00
Ed Page
2ffa38f9f5 feat(parser): Implicitly turn possible values into a value parser 2022-05-16 17:07:35 -05:00
Ed Page
f86d881e3a docs(parser): Polish ValueParser docs 2022-05-16 16:54:05 -05:00
Ed Page
d826ab9445 fix(derive): Move args to new 'get_one'/'get_many' API 2022-05-16 15:16:51 -05:00
Ed Page
72c44a32e5 fix(derive): Move subcommands to new 'get_many' API 2022-05-16 15:16:51 -05:00
Ed Page
41f13bd0ce feat(complete): Path value parsers imply Path completion hints 2022-05-16 15:15:55 -05:00
Ed Page
d2ca18130e feat(parser): Allow removing values from ArgMatches
This allows reducing the use of `Clone`, especially in `clap_derive`.
2022-05-16 15:08:47 -05:00
Ed Page
792fb54990 fix(parser): Be consistently strict with ArgMatches types
This gives us more implementation freedom for the future.
2022-05-16 15:08:47 -05:00
Ed Page
c7bd8c891d perf(parser): Don't allocate on every call 2022-05-16 15:08:47 -05:00