Commit graph

5672 commits

Author SHA1 Message Date
Ed Page
1428785677 fix(parser): Deprecate args_override_self
This shouldn't be needed anymore now that this is effectively the new
behavior for the non-deprecated actions.

This was briefly talked about in
https://github.com/clap-rs/clap/discussions/2627 but I wasn't familiar
enough with the implementation to know how safe it is.  Now, maintainrs
and users can be more confident because they are explicitly opting into
it.

See also #3795
2022-06-06 14:57:24 -05:00
Ed Page
a979cf9bb8 fix(parser): Deprecate max_occurrences 2022-06-06 14:09:24 -05:00
Ed Page
0ba63664fe feat(builder): Offer u64 ranges 2022-06-06 14:02:01 -05:00
Ed Page
1879826b21 fix(parser): Deprecate StoreValue / IncOccurrences Actions
Dropping these will help simplify a lot, including removing of
occurrences.

These come at the cost of the derive not yet supporting types that impl
`From`.
2022-06-06 13:41:27 -05:00
Ed Page
4a694f3592 refactor(parser): Be explicit in checking present values 2022-06-06 12:21:47 -05:00
Ed Page
805cce74c6
Merge pull request #3794 from epage/derive
feat(derive): Expose control over Actions
2022-06-06 12:07:34 -05:00
Ed Page
647896d929 feat(derive): Expose control over Actions
This is the derive support for #3774 (see also #3775, #3777)

This combined with `value_parser` replaces `parser`.  The main
frustration with this is that `ArgAction::Count` (the replacement for
`parse(from_occurrences)` must be a `u64`.  We could come up with a
magic attribute that is meant to be the value parser's parsed type.  We
could then use `TryFrom` to convert the parsed type to the user's type
to allow more.  That is an exercise for the future.  Alternatively, we
have #3792.

Prep for this included
- #3782
- #3783
- #3786
- #3789
- #3793
2022-06-06 11:35:07 -05:00
Ed Page
955f8b627a
Merge pull request #3793 from epage/required
fix(validator): Ignore defaults for requireds
2022-06-06 11:32:07 -05:00
Ed Page
4489f09f10 feat(parser): Allow querying whether actions take values 2022-06-06 11:20:08 -05:00
Ed Page
0f1de7303d fix(validator): Ignore defaults for requireds
This is a follow up to #3420.  Its easy to overlook this because it is only
useful for the conditionals (we actually prevent applying unconditional
defaults to unconditional requireds).  This became apparent with the
increased use of defaults with `SetTrue`.

As always, there is the question of when is a bug fix a breaking change.
I'm going to consider this safe since we prevent some instances of this
from even happening and we already did #3420 and this is in line with
those.
2022-06-06 11:07:04 -05:00
Ed Page
ac64391910 refactor(parser): Remove dead code 2022-06-06 10:15:28 -05:00
Ed Page
44e1095166
Merge pull request #3789 from epage/refactor
refactor: Prep for actions in derive
2022-06-04 13:46:39 -05:00
Ed Page
002204a122 test(derive): Update ui tests 2022-06-04 13:24:46 -05:00
Ed Page
9638f33d2f fix(parser): Exclusive shouldnt preclude defaults
Unsure why a comment said this doesn't matter.  It matters both for
counting arguments and for reporting the correct argument is exclusive.
2022-06-04 12:58:53 -05:00
Ed Page
f3bc3d5eb7 fix(error): Don't include default-but-required arguments in usage 2022-06-04 12:58:53 -05:00
Ed Page
a971346004 test(parser): Verify indices of defaults
I thought I had broken this but it always seemed to have worked this way
2022-06-04 12:58:53 -05:00
Ed Page
5f56e93c0f refactor(parser): Clarify we are working with ids, not names 2022-06-04 12:58:53 -05:00
Ed Page
ccd6663de9 fix(help): Output some bool possible values
Originally I hid all, assuming the flag-only use case but we had to
prevent that from showing up anyways.  For the takes_value case, we
should be showing something since we know what it accepts.  I decided to
only show the most basic values and hide the rest so as to not overwhelm
the user with redundant options and hope the user recognizes they are
redundant.
2022-06-04 12:58:53 -05:00
Ed Page
b09def1ad0 test(derive): Verify doc comments on ArgEnum 2022-06-04 12:58:53 -05:00
Ed Page
a3092bafce fix(help): Don't report flag defaults
Now that flags can have meaningful defaults and with defaults being
implicitly set for certain actions, they appear in help but don't quite
make sense.
2022-06-04 12:58:53 -05:00
Ed Page
11fbe7e54b test(derive): Improve help output assertions 2022-06-04 12:58:53 -05:00
Ed Page
52e2874c03 fix(builder): Make it easier to discover/access ArgAction 2022-06-04 12:58:53 -05:00
Ed Page
d56d8dd59e chore: Make it easy to reproduce CI docs run 2022-06-04 12:58:53 -05:00
Ed Page
844dbae96b
Merge pull request #3787 from epage/bench
refactor(bench): Pull out benchmarks into own crate
2022-06-03 14:09:20 -05:00
Ed Page
34368419c2 refactor(bench): Pull out benchmarks into own crate
This is mostly about avoiding criterion's build times when just
developing clap itself.

I'm assuming the derive test changed because criterion's clap v2 isn't
in the dependency tree anymore.
2022-06-03 13:51:26 -05:00
Ed Page
8dd7d64977
Merge pull request #3786 from epage/default
fix(parser): Provide default value for Actions
2022-06-03 10:24:50 -05:00
Ed Page
e4b443d8bb fix(parser): Provide default value for Actions
Actions were inspired by Python and Python does not implicitly default
any field when an action is given.  From a Builder API perspective, this
seemed fine because we tend to focus the Builder API on giving the user
all information so they can make their own decisions.  When working on
the Derive API, this became a problem because users were going to have
to migrate from an implied default to an explicit default when a common
default is good enough most of the time.  This shouldn't interfere with
Builder users getting more details when needed.

This also highlighted two problems
- We set the index for defaults
- We don't debug_assert when applying conditional requirements with a
  default present
2022-06-03 10:02:35 -05:00
Ed Page
e8ad62b784
Merge pull request #3783 from epage/refactor
refactor(derive): Prepare for action support
2022-06-03 09:56:56 -05:00
Ed Page
5db611384e test(derive): Ensure we don't break compatibility 2022-06-02 16:56:14 -05:00
Ed Page
002d4421e5 Revert "fix(parser): Don't treat missing values as missing args"
This reverts commit 50f4018dcf.

This broke compatibility with the derive when dealing with
`Option<Option<T>>` and related cases.
2022-06-02 16:56:14 -05:00
Ed Page
552e6feb3f fix(derive): Adjust precedence for flag/occurrence logic 2022-06-02 16:56:12 -05:00
Ed Page
f4004b653b refactor(derive): Give new-style highest precedence
This exposed a potential bug but I figure it isn't worth fixing without
actions.
2022-06-02 16:46:50 -05:00
Ed Page
ebf9c16a23 refactor(derive): Clarify functions role 2022-06-02 16:46:50 -05:00
Ed Page
cccc88bcc2 fix(derive): Fix typo in error messages 2022-06-02 16:46:50 -05:00
Ed Page
e5f2911603 fix(derive): Reference correct path 2022-06-02 16:46:50 -05:00
Ed Page
77a0e66f6e
Merge pull request #3782 from epage/parser
refactor(derive): Merge handling of bool/from_flag
2022-06-02 14:47:53 -05:00
Ed Page
58cf0ee446
Merge pull request #3781 from epage/get_one
fix(parser): Don't treat missing values as missing args
2022-06-02 14:04:56 -05:00
Ed Page
50f4018dcf fix(parser): Don't treat missing values as missing args 2022-06-02 13:45:18 -05:00
Ed Page
cc2714beab fix(parser): Don't allow error equality
This could cause surprising results for users as we add fields
2022-06-02 13:36:05 -05:00
Ed Page
773ba94c4e refactor(derive): Merge handling of bool/from_flag
This will make it easier to divide off parser logic for adding in
actions.

This does mean we can't provide error reporting on bad values with
`bool` but
- We should have also been doing that for `from_flag`
- We'll be dropping this soon in clap4 anyways
2022-06-02 13:01:59 -05:00
Ed Page
dfc55cd6e3 test(derive): Update ui test to be correct otherwise 2022-06-02 11:59:09 -05:00
Ed Page
e5ead4ce49 refactor(derive): Default parser based on type 2022-06-02 11:50:45 -05:00
Ed Page
f61aad4b34 refactor(derive): Resolve value parsers earlier 2022-06-02 11:14:25 -05:00
Ed Page
96ac83e260 refactor(derive): Simplify needs for finding the inner type 2022-06-02 11:07:43 -05:00
Ed Page
758f3fff18
Merge pull request #3779 from epage/docs
docs(builder): Note the type for 'Count'
2022-06-01 16:59:58 -05:00
Ed Page
ab08a3069a docs(builder): Note the type for 'Count' 2022-06-01 16:23:19 -05:00
Ed Page
ec9d180e11
Merge pull request #3778 from epage/unify
fix(derive): Align value parser's type with occurrences_of
2022-06-01 12:16:19 -05:00
Ed Page
bbab148289 fix(derive): Align value parser's type with occurrences_of 2022-06-01 11:21:34 -05:00
Ed Page
b417e62ccd
Merge pull request #3777 from epage/set
feat(builder): Set/Append Actions
2022-06-01 11:09:05 -05:00
Ed Page
95c812b411 feat(builder): Set/Append Actions
This round out the new style actions and allow us to start deprecating
occurrences.

As part of an effort to unify code paths, this does change flag parsing
to do splits.  This will only be a problem if the user enables splits
but we'll at least not crash.  Once we also address #3776, we'll be able
to have envs all work the same.
2022-06-01 10:12:44 -05:00