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

Usage help should not show space between short option name and parameter #531

Closed
remkop opened this issue Oct 27, 2018 · 1 comment
Closed
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Oct 27, 2018

When an option only has a short name, the usage help message shows a space between the option name and the parameter. This does not happen with long option names.

For example:

  -c= <configurationFile>    Sets the check configuration file to use.
  -C, --checker-threads-number=<checkerThreadsNumber>
                             (experimental) The number of Checker threads (must be greater than zero)
  -d, --debug                Print all debug logging of CheckStyle utility
  -e, --exclude=<exclude>    Directory path to exclude from CheckStyle
  -f= <format>               Sets the output format. Valid values: xml, plain. Defaults to plain
@remkop
Copy link
Owner Author

remkop commented Nov 9, 2018

Patch:

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 )
@@ -9016,6 +9016,9 @@
                 public Cell(int column, int row) { this.column = column; this.row = row; }
             }
 
+            private static final int OPTION_SEPARATOR_COLUMN = 2;
+            private static final int LONG_OPTION_COLUMN = 3;
+
             /** The column definitions of this table. */
             private final Column[] columns;
 
@@ -9138,6 +9141,7 @@
                             columns.length + " columns");
                 }
                 addEmptyRow();
+                int oldIndent = unindent(values);
                 for (int col = 0; col < values.length; col++) {
                     int row = rowCount() - 1;// write to last row: previous value may have wrapped to next row
                     Cell cell = putValue(row, col, values[col]);
@@ -9147,7 +9151,21 @@
                         addEmptyRow();
                     }
                 }
+                reindent(oldIndent);
             }
+            private int unindent(Text[] values) {
+                if (columns.length <= LONG_OPTION_COLUMN) { return 0; }
+                int oldIndent = columns[LONG_OPTION_COLUMN].indent;
+                if ("=".equals(values[OPTION_SEPARATOR_COLUMN].toString())) {
+                    columns[LONG_OPTION_COLUMN].indent = 0;
+                }
+                return oldIndent;
+            }
+            private void reindent(int oldIndent) {
+                if (columns.length <= LONG_OPTION_COLUMN) { return; }
+                columns[LONG_OPTION_COLUMN].indent = oldIndent;
+            }
+
             /**
              * Writes the specified value into the cell at the specified row and column and returns the last row and
              * column written to. Depending on the Column's {@link Column#overflow Overflow} policy, the value may span
@@ -9268,7 +9286,7 @@
             public final int width;
 
             /** Indent (number of empty spaces at the start of the column preceding the text value) */
-            public final int indent;
+            public int indent;
 
             /** Policy that determines how to handle values larger than the column width. */
             public final Overflow overflow;

@remkop remkop added this to the 3.7.1 milestone Nov 10, 2018
@remkop remkop closed this as completed in 9e092f6 Nov 10, 2018
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