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

Requires and Conflicts should ignore default_value #3020

Closed
wants to merge 3 commits into from

Conversation

pksunkara
Copy link
Member

@pksunkara pksunkara commented Nov 13, 2021

As expected, this was caused because of a bad abstraction.

Fixes #3076

@@ -25,7 +25,7 @@ static ONLY_C_ERROR: &str = "error: The following required arguments were not pr
-b

USAGE:
prog [OPTIONS] -b -c
prog [OPTIONS] -c -b
Copy link
Member Author

Choose a reason for hiding this comment

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

The changes in this file are intentional because the earlier messages were wrong. We always show existing arguments first in other cases too.

@kbknapp
Copy link
Member

kbknapp commented Nov 16, 2021

@pksunkara could you elaborate on the issue at hand along with the fix? It'll make reviewing the code and how it fits into the overall project much easier. I can understand if you have full context, but speaking for myself I don't 😄

@pksunkara
Copy link
Member Author

Basically, we used a common function to validate requirements and then also to build the error message if requirements fail.

But they should actually be two different functions since the logic inside validation is actually different to the one in the other.

This issue surfaced because of #2985 and this PR is to separate out the logic for those functions.

@kbknapp
Copy link
Member

kbknapp commented Nov 16, 2021

Hmm, this sounds like maybe it's a symptom of a larger issue. Is there an issue you can point to, or do we need to create one with all the details? I'd rather prioritize v3 issues, and if this is a long standing issue, or one in which it's more deeply rooted than addressing the surface I'd prefer to look at it that way.

@pksunkara
Copy link
Member Author

Yeah, the usage string generation (used in error messages) has been a long standing issue but we never discovered this specific part until #2985 was merged. Because of that, a regression in error message has been created.

We have many usage string bugs that I tagged as 3.1 previously that I planned to make priority after v3 release.

@pksunkara pksunkara requested a review from ldm0 December 7, 2021 00:32
@epage epage mentioned this pull request Dec 7, 2021
2 tasks
@pksunkara pksunkara linked an issue Dec 9, 2021 that may be closed by this pull request
2 tasks
@pksunkara pksunkara added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 9, 2021
@pksunkara
Copy link
Member Author

I updated this and we should be looking at it after 3.0

@pksunkara pksunkara changed the title Fix a regression with unrolling requirements in usage string Requires and Conflicts should ignore default_value Dec 9, 2021
@epage epage added this to the 3.1 milestone Dec 9, 2021
@epage
Copy link
Member

epage commented Jan 4, 2022

@pksunkara could you rebase this when you have a chance?

@epage epage added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jan 4, 2022
epage added a commit to epage/clap that referenced this pull request Feb 1, 2022
While this doesn't help in the public API (yet), this at least clarifies
the intent in the implementation.

This is building towards clap-rs#3020.
epage added a commit to epage/clap that referenced this pull request Feb 2, 2022
For some errors, we use the unroll logic to get the list of required
arguments.  The usage then does the same, but without a matcher.  This
was causing the lists to not match.

As a side effect, this fixed an ordering issue where we were putting the
present arg after the not-present arg.  I assume its because we ended up
reporting the items twice but the first time is correctly ordered and
gets precedence.

This was split out of clap-rs#3020
@epage epage removed this from the 3.x milestone Feb 2, 2022
epage added a commit to epage/clap that referenced this pull request Feb 8, 2022
epage added a commit to epage/clap that referenced this pull request Feb 8, 2022
Unrolling serves two distinct purposes but we muddied them together
- Is `requires` satisfied for validation
- Report what arguments are currently considered required for usage

This was split out of clap-rs#3020
@epage epage closed this Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Require rules ignore a defaulted value
3 participants