Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): SetTrue/SetFalse/Count Actions #3775

Merged
merged 5 commits into from
Jun 1, 2022
Merged

Conversation

epage
Copy link
Member

@epage epage commented Jun 1, 2022

This is the minimum set of actions for the derive to move off of
parse. These are inspired by Python's native actions.

These new actions have a "unified" behavior with defaults/envs. This
mostly means that occurrences aren't tracked. Occurrences were used as
a substitute for ValueSource or for counting values. Both cases
shouldn't be needed anymore but we can re-evaluate this later if needed.

There is room for performance improvements where we reuse allocations but we can worry about that as a profiler says its a case to care about.

Now that we can store constants for flags, we can apply defaults for
flags too.

Fixes #3294

epage added 4 commits May 31, 2022 21:21
This is the minimum set of actions for the derive to move off of
`parse`.  These are inspired by Python's native actions.

These new actions have a "unified" behavior with defaults/envs.  This
mostly means that occurrences aren't tracked.  Occurrences were used as
a substitute for `ValueSource` or for counting values.  Both cases
shouldn't be needed anymore but we can re-evaluate this later if needed.
Now that we can store constants for flags, we can apply defaults for
flags too.

Fixes clap-rs#3294
@epage epage merged commit 7076752 into clap-rs:master Jun 1, 2022
@epage epage deleted the new branch June 1, 2022 12:07
epage added a commit to epage/clap that referenced this pull request Jun 6, 2022
This is the derive support for clap-rs#3774 (see also clap-rs#3775, clap-rs#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 clap-rs#3792.

Prep for this included
- clap-rs#3782
- clap-rs#3783
- clap-rs#3786
- clap-rs#3789
- clap-rs#3793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default_value_if should work with flags that don't take a value
1 participant