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

Incorrect help message for short options with paramLabel when arity > 1 #181

Closed
remkop opened this issue Sep 3, 2017 · 1 comment
Closed
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Sep 3, 2017

This only happens for short options, not when an option has either both a short and a long option or just long options.

The help message looks like this. Note the double = and the missing opening square bracket [ in the options list:

Usage: <main class> [-f[=FILE...]] [-P[=KEY=VALUE...]] 
  -f= =FILE...]               files
  -P= =KEY=VALUE...]          Project properties (key-value pairs)

When a long option is specified, or arity=1, things look okay:

Usage: <main class> [-f=FILE] [-P[=KEY=VALUE...]]
  -f= FILE                    a file
  -P, --properties[=KEY=VALUE...]
                              Project properties (key-value pairs)
@remkop remkop added this to the 1.1.0 milestone Sep 3, 2017
remkop added a commit that referenced this issue Sep 3, 2017
@remkop
Copy link
Owner Author

remkop commented Sep 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 )
@@ -2990,7 +2990,10 @@
                 // if no long option, fill in the space between the short option name and the param label value
                 if (paramLabelText.length > 0 && longOption.length() == 0) {
                     sep = paramLabelRenderer.separator();
-                    paramLabelText = paramLabelText.substring(sep.length());
+                    // #181 paramLabelText may be =LABEL or [=LABEL...]
+                    int sepStart = paramLabelText.plainString().indexOf(sep);
+                    Text prefix = paramLabelText.substring(0, sepStart);
+                    paramLabelText = prefix.append(paramLabelText.substring(sepStart + sep.length()));
                 }
                 Text longOptionText = scheme.optionText(longOption);
                 longOptionText = longOptionText.append(paramLabelText);

@remkop remkop closed this as completed in e06ff90 Sep 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