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

fix: Remove overriden occurrences as we go #3225

Merged
merged 5 commits into from
Dec 27, 2021
Merged

Conversation

epage
Copy link
Member

@epage epage commented Dec 27, 2021

This allows two overriding args to interact with each other mid-line.
This was broken in 7673dfc / #1154. Before that, we duplicated the override
logic in several places.

Now we plug into the start of a new arg which allows us to do this
incrementally without making the logic complex or inefficient, thanks to
the refactors in this PR.

Fixes #3217

This makes some naming more explicit and allows us to increment
occurrences before adding values (which is the logical mental order and
allows other improvements).
This is the logical order people think in terms of (`--foo` comes before
`val` in `--foo val`). This also opens things up for using occurrence
incrementing as a place to handle occurrence transitions, like
overrides.
This will have a slight performance hit as `AllArgsOverrideSelf` will
allocate a single-element `Vec` per `Arg`.  This can be lessened for
positional and multiple occurrences by shifting those checks up into the
propagation check.

Long term, I'd like to see all of the `Arg`-in-`App` settings switch to
this which will make it easier for callers, like completions and man
pages, to figure out whats going on without duplicating the logic.

Short term, this is motivated by wanting to change the override logic to
accomodated interleaved overrides from clap-rs#3217.  Moving this logic will
make it easier to change the override logic.
This allows two overriding args to interact with each other mid-line.
This was broken in 7673dfc / clap-rs#1154.  Before that, we duplicated the override
logic in several places.

Now we plug into the start of a new arg which allows us to do this
incrementally without making the logic complex or inefficient, thanks to
prior refactors.

Fixes clap-rs#3217
@epage epage added the M-unreviewed Meta: Request for post-merge review. label Dec 27, 2021
@epage epage merged commit a58c164 into clap-rs:master Dec 27, 2021
@epage epage deleted the override branch December 27, 2021 21:55
//
// We can evaluate switching this to a debug assert at a later time (though it will
// require changing propagation of `AllArgsOverrideSelf`). Being conservative for now
// due to where we are at in the release.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we released, can we add a debug assert for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing so would be a breaking change. This was written assuming we wouldn't be changing it for 3.x because it didn't seem worth addressing in our current time frame.

@pksunkara pksunkara removed the M-unreviewed Meta: Request for post-merge review. label Jan 1, 2022
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.

Flags that take multiple value cannot be partially overridden
2 participants