Skip to content

Commit

Permalink
[#311] Enhancement and API change: Simplify parseWithHandlers: remove…
Browse files Browse the repository at this point in the history
…d prototypeReturnValue parameter.

Closes #311.
  • Loading branch information
remkop committed Mar 27, 2018
1 parent a59c31f commit 6ab2156
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 92 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# <a name="3.0.0-alpha-2"></a> Picocli 3.0.0-alpha-2 (UNRELEASED)
## <a name="3.0.0-alpha-2-fixes"></a> Fixed issues

- [#311] Enhancement and API change: Simplify parseWithHandlers: removed prototypeReturnValue parameter.
- [#307] Enhancement: Provide CommandLine.usage(PrintWriter) method for testing and to facilitate [GROOVY-8520](https://issues.apache.org/jira/browse/GROOVY-8520) migration from commons-cli to picocli.
- [#306] Enhancement: Support generating autocompletion scripts for non-public @Command classes. Thanks to [cbeams](https://github.com/cbeams) for the request.
- [#308] Enhancement: Provide API to disallow POSIX clustered short options.
Expand All @@ -13,6 +14,8 @@
See [3.0.0-alpha-1]()#3.0.0-alpha-1-deprecated)

## <a name="3.0.0-alpha-2-breaking-changes"></a> Potential breaking changes
- [#311] This is an API change from 3.0.0-alpha-1: the `parseWithHandlers` methods signature changed: removed the `prototypeReturnValue` parameter.

See [3.0.0-alpha-1]()#3.0.0-alpha-1-breaking-changes)

# <a name="3.0.0-alpha-1"></a> Picocli 3.0.0-alpha-1
Expand Down
4 changes: 2 additions & 2 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ and `useAnsi` to customize the Ansi style to use:
cmd.parseWithHandlers(
new RunLast().useOut(myOut).useAnsi(Help.Ansi.ON),
new DefaultExceptionHandler().useErr(myErr).useAnsi(Help.Ansi.OFF),
CommandLine.defaultExceptionHandler().useErr(myErr).useAnsi(Help.Ansi.OFF),
args);
}
}
Expand All @@ -2245,7 +2245,7 @@ If an exit code was specified, the handler terminates the JVM with the specified
CommandLine cmd = new CommandLine(new ExitCodeDemo());
cmd.parseWithHandlers(
new RunLast().andExit(123),
new DefaultExceptionHandler().andExit(456),
CommandLine.defaultExceptionHandler().andExit(456),
args);
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/java/picocli/examples/ExitCodeDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static void main(String... args) {
CommandLine cmd = new CommandLine(new ExitCodeDemo());
cmd.parseWithHandlers(
new CommandLine.RunLast().andExit(123),
Collections.<Object>emptyList(),
new CommandLine.DefaultExceptionHandler<List<Object>>().andExit(456),
CommandLine.defaultExceptionHandler().andExit(456),
args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public static void main(final String[] args) {
CommandLine commandLine = new CommandLine(spec);

class Handler extends AbstractParseResultHandler<Void> {
public Void handle(ParseResult pr, Void retVal) {
public Void handle(ParseResult pr) {
int count = pr.optionValue('c', 1);
List<File> files = pr.positionalValue(pr.positionalParams().get(0), Collections.<File>emptyList());
for (File f : files) {
for (int i = 0; i < count; i++) {
System.out.println(i + " " + f.getName());
}
}
return retVal;
return null;
}
protected Handler self() { return this; }
}

commandLine.parseWithHandler(new Handler(), null, args);
commandLine.parseWithHandler(new Handler(), args);
}
}
Loading

0 comments on commit 6ab2156

Please sign in to comment.