From 9f6ef2a7006f951a233b2dee7fae7b07762013be Mon Sep 17 00:00:00 2001 From: Remko Popma Date: Sat, 26 Aug 2023 10:53:06 +0900 Subject: [PATCH] [#2059] ArgGroup fix regression and refine solution introduced in [#1848][#2030] --- RELEASE-NOTES.md | 1 + src/main/java/picocli/CommandLine.java | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index b84da06b8..c475a4966 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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. ## Deprecations diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index cd20ede00..1b721f2f7 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -13028,8 +13028,27 @@ void validate(CommandLine commandLine) { } } - private boolean containsRequiredOptionsOrSubgroups(ArgGroupSpec argGroupSpec) { - return containsRequiredOptionsOrParameters(argGroupSpec) || containsRequiredSubgroups(argGroupSpec); + /** + * A group is optional if + * + * Conversely, a group is required if + * @see https://github.com/remkop/picocli/issues/1848 + * and https://github.com/remkop/picocli/issues/2059 + */ + private boolean isGroupEffectivelyOptional(ArgGroupSpec argGroupSpec) { + if (argGroupSpec.multiplicity().min == 0) {return true; } + return requiredOptionsExistAndAllHaveDefaultValues(argGroupSpec) && !containsRequiredSubgroups(argGroupSpec); } private boolean containsRequiredOptionsOrParameters(ArgGroupSpec argGroupSpec) {