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

Show more precise usage help for options/parameters with split regex #194

Closed
remkop opened this issue Sep 30, 2017 · 2 comments
Closed

Show more precise usage help for options/parameters with split regex #194

remkop opened this issue Sep 30, 2017 · 2 comments

Comments

@remkop
Copy link
Owner

remkop commented Sep 30, 2017

For example,

class Args {
    @Option(names = "-o", split = ",", paramLabel = "ARGS") List<String> options;
}

Usage help could show:

Usage: <main class> [-o=ARGS[,ARGS]...]...
 -o= ARGS[,ARGS]...
@remkop remkop added this to the 2.0.0 milestone Sep 30, 2017
@remkop
Copy link
Owner Author

remkop commented Oct 4, 2017

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	(revision )
+++ src/main/java/picocli/CommandLine.java	(revision )
@@ -3173,9 +3173,11 @@
             public Text renderParameterLabel(Field field, Ansi ansi, List<IStyle> styles) {
                 boolean isOptionParameter = field.isAnnotationPresent(Option.class);
                 Range arity = isOptionParameter ? Range.optionArity(field) : Range.parameterArity(field);
+                String split = isOptionParameter ? field.getAnnotation(Option.class).split() : field.getAnnotation(Parameters.class).split();
                 Text result = ansi.new Text("");
                 String sep = isOptionParameter ? separator : "";
                 Text paramName = ansi.apply(renderParameterName(field), styles);
+                if (!empty(split)) { paramName = paramName.append("[" + split).append(paramName).append("]..."); } // #194
                 for (int i = 0; i < arity.min; i++) {
                     result = result.append(sep).append(paramName);
                     sep = " ";

@remkop
Copy link
Owner Author

remkop commented Oct 4, 2017

Index: src/test/java/picocli/CommandLineHelpTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/java/picocli/CommandLineHelpTest.java	(revision )
+++ src/test/java/picocli/CommandLineHelpTest.java	(revision )
@@ -2286,22 +2286,24 @@
     @Test
     public void testMapFieldHelp() throws Exception {
         class App {
-            @Parameters(arity = "2", split = "\\|", type = {Integer.class, String.class},
+            @Parameters(arity = "2", split = "\\|",
                     paramLabel = "FIXTAG=VALUE",
                     description = "Exactly two lists of vertical bar '|'-separated FIXTAG=VALUE pairs.")
             Map<Integer,String> message;
 
-            @Option(names = {"-P", "-map"}, split = ",", type = {TimeUnit.class, String.class},
+            @Option(names = {"-P", "-map"}, split = ",",
                     paramLabel = "TIMEUNIT=VALUE",
                     description = "Any number of TIMEUNIT=VALUE pairs. These may be specified separately (-PTIMEUNIT=VALUE) or as a comma-separated list.")
             Map<TimeUnit, String> map;
         }
         String actual = usageString(new App(), Help.Ansi.OFF);
         String expected = String.format("" +
-                "Usage: <main class> [-P=TIMEUNIT=VALUE]... FIXTAG=VALUE FIXTAG=VALUE%n" +
+                "Usage: <main class> [-P=TIMEUNIT=VALUE[,TIMEUNIT=VALUE]...]... FIXTAG=VALUE%n" +
+                "                    [\\|FIXTAG=VALUE]... FIXTAG=VALUE[\\|FIXTAG=VALUE]...%n" +
                 "      FIXTAG=VALUE            Exactly two lists of vertical bar '|'-separated%n" +
                 "                                FIXTAG=VALUE pairs.%n" +
-                "  -P, -map=TIMEUNIT=VALUE     Any number of TIMEUNIT=VALUE pairs. These may be%n" +
+                "  -P, -map=TIMEUNIT=VALUE[,TIMEUNIT=VALUE]...%n" +
+                "                              Any number of TIMEUNIT=VALUE pairs. These may be%n" +
                 "                                specified separately (-PTIMEUNIT=VALUE) or as a%n" +
                 "                                comma-separated list.%n");
         assertEquals(expected, actual);

@remkop remkop closed this as completed in 0e7508c Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant