Skip to content

Commit

Permalink
[#2059] ArgGroup fix regression and refine solution introduced in [#1848
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Aug 26, 2023
1 parent 3c298af commit 9f6ef2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).
* [#2060] Bugfix: Fix positional parameters bug with late-resolved arity variable. Thanks to [daisukeoto](https://github.com/daisukeoto) for raising this.
* [#2074][#2075] Bugfix: Don't generate auto-complete for hidden attributes in `picocli.shell.jline3.PicoCommand`. Thanks to [clebertsuconic](https://github.com/clebertsuconic) for the pull request.
* [#2083][#2084] Enhancement: Java 22 update: improve logic for detecting if the output stream is connected to a terminal. Thanks to [Liam Miller-Cushon](https://github.com/cushon) for the pull request.
* [#2059] Bugfix: ArgGroup with `exclusive=false` and `multiplicity=1` should require at least one option; fix regression and refine solution introduced in [#1848][#2030]. Thanks to [Utkarsh Mittal](https://github.com/utmittal) for raising this.
* [#2080] DOC: Improve GraalVM documentation: add `graalvm-native-image-plugin`. Thanks to [Bhavik Patel](https://github.com/bhavikp19) for the pull request.

## <a name="4.7.5-deprecated"></a> Deprecations
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13028,8 +13028,27 @@ void validate(CommandLine commandLine) {
}
}

private boolean containsRequiredOptionsOrSubgroups(ArgGroupSpec argGroupSpec) {
return containsRequiredOptionsOrParameters(argGroupSpec) || containsRequiredSubgroups(argGroupSpec);
/**
* A group is optional if <ul>
* <li>its minimum <code>multiplicity</code> is zero</li>
* <li>otherwise, if the group has at least one required option and all required options have default values</li>
* </ul>
*
* Conversely, a group is required if <ul>
* <li>if its minimum <code>multiplicity</code> is <code>1</code> or more <em>AND</em></li>
* <li>
* <ul>
* <li>either the group has no required options</li>
* <li>or the group has at least one required option without a default value</li>
* </ul>
* </li>
* </ul>
* @see <a href="https://github.com/remkop/picocli/issues/1848">https://github.com/remkop/picocli/issues/1848</a>
* and <a href="https://github.com/remkop/picocli/issues/2059">https://github.com/remkop/picocli/issues/2059</a>
*/
private boolean isGroupEffectivelyOptional(ArgGroupSpec argGroupSpec) {
if (argGroupSpec.multiplicity().min == 0) {return true; }
return requiredOptionsExistAndAllHaveDefaultValues(argGroupSpec) && !containsRequiredSubgroups(argGroupSpec);
}

private boolean containsRequiredOptionsOrParameters(ArgGroupSpec argGroupSpec) {
Expand Down

0 comments on commit 9f6ef2a

Please sign in to comment.