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

ArgGroup synopsis should respect order (if specified) #964

Closed
remkop opened this issue Feb 27, 2020 · 0 comments
Closed

ArgGroup synopsis should respect order (if specified) #964

remkop opened this issue Feb 27, 2020 · 0 comments
Labels
theme: arg-group An issue or change related to argument groups theme: usagehelp An issue or change related to the usage help message type: enhancement ✨
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Feb 27, 2020

See this StackOverflow question: https://stackoverflow.com/questions/60424395/cannot-create-cli-with-specific-with-synopsis-cli-with-picocli

It turns out that the order of elements in the synopsis cannot be affected by the order attribute.
Investigate if it is feasible to control the synopsis with the order attribute.


Note to self:

Index: src/main/java/picocli/CommandLine.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/picocli/CommandLine.java	(date 1582775601204)
+++ src/main/java/picocli/CommandLine.java	(date 1582775601204)
@@ -8893,18 +8893,28 @@
             private Text rawSynopsisUnitText(Help.ColorScheme colorScheme, Set<ArgSpec> outparam_groupArgs) {
                 String infix = exclusive() ? " | " : " ";
                 Text synopsis = colorScheme.ansi().new Text(0);
+
+                List<IOrdered> sortableComponents = new ArrayList<IOrdered>();
+                List<PositionalParamSpec> remainder = new ArrayList<PositionalParamSpec>();
                 for (ArgSpec arg : args()) {
+                    if (arg instanceof OptionSpec) { sortableComponents.add((IOrdered) arg); }
+                    else { remainder.add((PositionalParamSpec) arg); }
+                }
+                sortableComponents.addAll(subgroups());
+                Collections.sort(sortableComponents, new Help.SortByOrder<IOrdered>());
+                for (IOrdered ordered : sortableComponents) {
                     if (synopsis.length > 0) { synopsis = synopsis.concat(infix); }
-                    if (arg instanceof OptionSpec) {
-                        synopsis = concatOptionText(synopsis, colorScheme, (OptionSpec) arg);
+                    if (ordered instanceof OptionSpec) {
+                        synopsis = concatOptionText(synopsis, colorScheme, (OptionSpec) ordered);
+                        outparam_groupArgs.add((OptionSpec) ordered);
                     } else {
-                        synopsis = concatPositionalText(synopsis, colorScheme, (PositionalParamSpec) arg);
+                        synopsis = synopsis.concat(((ArgGroupSpec) ordered).synopsisText(colorScheme, outparam_groupArgs));
                     }
-                    outparam_groupArgs.add(arg);
                 }
-                for (ArgGroupSpec subgroup : subgroups()) {
+                for (PositionalParamSpec positional : remainder) {
                     if (synopsis.length > 0) { synopsis = synopsis.concat(infix); }
-                    synopsis = synopsis.concat(subgroup.synopsisText(colorScheme, outparam_groupArgs));
+                    synopsis = concatPositionalText(synopsis, colorScheme, (PositionalParamSpec) positional);
+                    outparam_groupArgs.add(positional);
                 }
                 return synopsis;
             }
@remkop remkop added this to the 4.3 milestone Feb 27, 2020
@remkop remkop added the theme: usagehelp An issue or change related to the usage help message label Apr 14, 2020
@remkop remkop modified the milestones: 4.3, 4.4 Apr 14, 2020
@remkop remkop modified the milestones: 4.4, 4.5 May 21, 2020
@remkop remkop modified the milestones: 4.5.2, 4.6, 4.7 Oct 14, 2020
remkop pushed a commit that referenced this issue Feb 8, 2022
@remkop remkop changed the title Synopsis should respect order (if specified) ArgGroup synopsis should respect order (if specified) Feb 14, 2022
@remkop remkop added the theme: arg-group An issue or change related to argument groups label Feb 14, 2022
@remkop remkop closed this as completed in ee3f60b Feb 14, 2022
remkop added a commit that referenced this issue Feb 14, 2022
…hould be sorted alphabetically or via `order`.

Closes #1408
Closes #1574
remkop added a commit that referenced this issue Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: arg-group An issue or change related to argument groups theme: usagehelp An issue or change related to the usage help message type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

1 participant