-
Notifications
You must be signed in to change notification settings - Fork 431
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
ArgGroup with exclusive=false and multiplicity=1 not behaving as expected #2059
Comments
Maybe this could be added to the test cases to prevent the regression, also to test it on previous versions. |
None of the options in the Should this be changed? I am not sure... The current logic does make logical sense to me, it allows groups that have one optional and one required option to work as expected. For your use case, I would recommend making all options in the group I am not sure when the validation changed; I don't remember intentionally changing it but I could have forgotten... 😅 |
The use case I am trying to solve for is when at least one of the options is required. I.e. a user should be able to say If I set all the options to A colleague also helped track down this past issue: #947 which addresses our exact use case. The approach suggested there is exactly the one I have outlined in the minimal code above. I can work around this problem fairly easily by adding custom validation to throw a |
Ouch! Thanks for that link. Now it does look like a regression! 😅 I'll be traveling the next 2 weeks but I'll look at it when I get back. |
No problem! Thanks in advance for looking into it (and creating picocli)! We love picocli in our team :) |
@remkop really sorry to re-ping you here, but I was wondering if you already had / already still planning to have a look at this one? |
Thanks for the reminder! I'll try to take a look this weekend. |
@remkop thank you! Were you hoping to find the time for fixing this yourself? Or do you need or would welcome contributions, if anyone (not me...) was motivated to? |
I have been poking at this problem this week. I have a potential solution which probably requires a fair bit of polish to actually work. But basically, I would remove the method added in [4b41a21] and instead add logic in the Example:
I.e. if you have an ArgGroup with multiplicity=1 and an Option within it that has a default value, the multiplicity will become 0..1. If you have multiplicity=3 and 2 options are defaulted, the multiplicity becomes 1..3. This calculation probably needs some more thought to cover all the edge cases. This should handle both this issue and #1848. @remkop What do you think? Am I breaking some implicit assumption within the codebase by having the "actual" multiplicity be different to the "defined" multiplicity? |
Should be fixed in main now. Thank you again for raising this! |
Here's a minimal example to illustrate the problem:
With this example, I would expect that the command without any options (i.e.
multiplicity
), would throw a MissingParameterException. However, in the current version (4.7.4) the command executes and thecall()
method is executed. Note, that therequiredGroup
object is null.On a much older version of picocli (4.1.4), running this command works as expected. It throws a MissingParameterException with the text
Error: Missing required argument(s):
.I am not sure exactly where the regression happened or if this is even a regression? From my reading of the docs, it does seem like one. In the ArgGroup documentation:
The text was updated successfully, but these errors were encountered: