Skip to content

Commit

Permalink
[#531] Usage help should not show space between short option name and…
Browse files Browse the repository at this point in the history
… parameter (for options that only have a short name).

Closes #531
  • Loading branch information
remkop committed Nov 10, 2018
1 parent 86aff43 commit 9e092f6
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 101 deletions.
44 changes: 30 additions & 14 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
# picocli Release Notes


# <a name="3.7.1"></a> Picocli 3.7.1 (UNRELEASED)
The picocli community is pleased to announce picocli 3.7.1.
# <a name="3.8.0"></a> Picocli 3.8.0 (UNRELEASED)
The picocli community is pleased to announce picocli 3.8.0.

This release contains bugfixes and minor enhancements.


Many thanks to the many members of the picocli community who contributed!

This is the forty-second public release.
Picocli follows [semantic versioning](http://semver.org/).
Picocli follows [semantic versioning](http://semver.org/). (This release could have been called 3.7.1 except that it has a minor additional API change, which means it cannot be called a patch release by semver rules.)

## <a name="3.7.1"></a> Table of Contents
* [New and noteworthy](#3.7.1-new)
* [Fixed issues](#3.7.1-fixes)
* [Deprecations](#3.7.1-deprecated)
* [Potential breaking changes](#3.7.1-breaking-changes)
## <a name="3.8.0"></a> Table of Contents
* [New and noteworthy](#3.8.0-new)
* [Fixed issues](#3.8.0-fixes)
* [Deprecations](#3.8.0-deprecated)
* [Potential breaking changes](#3.8.0-breaking-changes)

## <a name="3.7.1-new"></a> New and Noteworthy
## <a name="3.8.0-new"></a> New and Noteworthy

## <a name="3.7.1-fixes"></a> Fixed issues
## <a name="3.8.0-fixes"></a> Fixed issues
- [#525] Enhancement: Allow `@Mixin` parameters in `@Command` methods. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request.
- [#532] Enhancement: `OverwrittenOptionException` now has an accessor for the `ArgSpec` that was overwritten. Thanks to [Steven Fontaine](https://github.com/acid1103) for the pull request.
- [#524] Enhancement/Bugfix: `ReflectionConfigGenerator` in `picocli-codegen` should generate configuration for `@Mixin` fields. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request.
- [#523] Bugfix: Array should be initialized before calling setter method. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request.
- [#527] Bugfix: Quoting logic did not work for some Unicode code points
- [#527] Bugfix: Quoting logic did not work for some Unicode code points.
- [#531] Bugfix: Usage help should not show space between short option name and parameter (for options that only have a short name).
- [#528] Doc: javadoc for xxxHandler API referred to non-existant prototypeReturnValue.

## <a name="3.7.1-deprecated"></a> Deprecations
## <a name="3.8.0-deprecated"></a> Deprecations
No features were deprecated in this release.

## <a name="3.7.1-breaking-changes"></a> Potential breaking changes
This release has no breaking changes.
## <a name="3.8.0-breaking-changes"></a> Potential breaking changes
The usage help no longer shows a space between short option names and the parameter (for options that only have a short name).
This may break tests that rely on the exact output format.

Before:
```
Usage: times [-l=<arg0>] [-r=<arg1>]
-l= <arg0>
-r= <arg1>
```

After:
```
Usage: times [-l=<arg0>] [-r=<arg1>]
-l=<arg0>
-r=<arg1>
```



Expand Down
20 changes: 19 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9016,6 +9016,9 @@ public static class Cell {
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;

Expand Down Expand Up @@ -9138,6 +9141,7 @@ public void addRowValues(Text... values) {
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]);
Expand All @@ -9147,7 +9151,21 @@ public void addRowValues(Text... values) {
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
Expand Down Expand Up @@ -9268,7 +9286,7 @@ public enum Overflow { TRUNCATE, SPAN, WRAP }
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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/picocli/CommandLineCommandMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ public void testCommandMethodMixinHelp() {
String expected = String.format("" +
"Usage: times [-hV] [-l=<arg0>] [-r=<arg1>]%n" +
" -h, --help Show this help message and exit.%n" +
" -l= <arg0>%n" +
" -r= <arg1>%n" +
" -l=<arg0>%n" +
" -r=<arg1>%n" +
" -V, --version Print version information and exit.%n" +
"");
assertEquals(expected, systemOutRule.getLog());
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/picocli/CommandLineDefaultProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ public void testDefaultValueInDescription() {
" Default: Default provider string value%n" +
" [<paramStringFieldWithInitDefault>]%n" +
" Default: Default provider string value%n" +
" -a= <optionStringFieldWithoutDefaultNorInitialValue>%n" +
" -a=<optionStringFieldWithoutDefaultNorInitialValue>%n" +
" Default: Default provider string value%n" +
" -b= <optionStringFieldWithAnnotatedDefault>%n" +
" -b=<optionStringFieldWithAnnotatedDefault>%n" +
" Default: Default provider string value%n" +
" -c= <optionStringFieldWithInitDefault>%n" +
" -c=<optionStringFieldWithInitDefault>%n" +
" Default: Default provider string value%n" +
" Default: Default provider string value%n" +
" -d= <string> Default: Default provider string value%n");
" -d=<string> Default: Default provider string value%n");
CommandLine cmd = new CommandLine(App.class);
assertEquals(expected, cmd.getUsageMessage(CommandLine.Help.Ansi.OFF));
}
Expand All @@ -189,14 +189,14 @@ public void testDefaultValueInDescriptionAfterSetProvider() {
" Default: XYZ%n" +
" [<paramStringFieldWithInitDefault>]%n" +
" Default: XYZ%n" +
" -a= <optionStringFieldWithoutDefaultNorInitialValue>%n" +
" -a=<optionStringFieldWithoutDefaultNorInitialValue>%n" +
" Default: XYZ%n" +
" -b= <optionStringFieldWithAnnotatedDefault>%n" +
" -b=<optionStringFieldWithAnnotatedDefault>%n" +
" Default: XYZ%n" +
" -c= <optionStringFieldWithInitDefault>%n" +
" -c=<optionStringFieldWithInitDefault>%n" +
" Default: XYZ%n" +
" Default: XYZ%n" +
" -d= <string> Default: XYZ%n");
" -d=<string> Default: XYZ%n");
CommandLine cmd = new CommandLine(App.class);
cmd.setDefaultValueProvider(new IDefaultValueProvider() {
public String defaultValue(ArgSpec argSpec) throws Exception {
Expand All @@ -217,14 +217,14 @@ public void testDefaultValueInDescriptionWithErrorProvider() {
" Default: Annotated default value%n" +
" [<paramStringFieldWithInitDefault>]%n" +
" Default: Initial default value%n" +
" -a= <optionStringFieldWithoutDefaultNorInitialValue>%n" +
" -a=<optionStringFieldWithoutDefaultNorInitialValue>%n" +
" Default: null%n" +
" -b= <optionStringFieldWithAnnotatedDefault>%n" +
" -b=<optionStringFieldWithAnnotatedDefault>%n" +
" Default: Annotated default value%n" +
" -c= <optionStringFieldWithInitDefault>%n" +
" -c=<optionStringFieldWithInitDefault>%n" +
" Default: Initial default value%n" +
" Default: Initial default value%n" +
" -d= <string> Default: Annotated setter default value%n");
" -d=<string> Default: Annotated setter default value%n");
CommandLine cmd = new CommandLine(App.class);
cmd.setDefaultValueProvider(new IDefaultValueProvider() {
public String defaultValue(ArgSpec argSpec) throws Exception {
Expand Down
Loading

0 comments on commit 9e092f6

Please sign in to comment.