Skip to content

Commit

Permalink
[#1127] colors in ShortErrorMessageHandler manual example
Browse files Browse the repository at this point in the history
Closes #1127
  • Loading branch information
remkop committed Jul 15, 2020
1 parent 2ff703e commit 1bae8a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Picocli follows [semantic versioning](http://semver.org/).

## <a name="4.4.1-fixes"></a> Fixed issues
* [#1124] Enhancement: automatically generate a better summary in the `AutoComplete.GenerateCompletion` generated man page.

* [#1127] DOC: Custom ShortErrorMessageHandler manual example should use bold red for error message.

## <a name="4.4.1-deprecated"></a> Deprecations
No features were deprecated in this release.
Expand Down
8 changes: 6 additions & 2 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2251,13 +2251,17 @@ class ShortErrorMessageHandler implements IParameterExceptionHandler {
CommandLine cmd = ex.getCommandLine();
PrintWriter writer = cmd.getErr();
writer.println(ex.getMessage());
writer.println(cmd.getColorScheme().errorText(ex.getMessage())); // bold red
UnmatchedArgumentException.printSuggestions(ex, writer);
writer.print(cmd.getHelp().fullSynopsis()); // since 4.1
writer.print(cmd.getHelp().fullSynopsis());
CommandSpec spec = cmd.getCommandSpec();
writer.printf("Try '%s --help' for more information.%n", spec.qualifiedName());
if ("DEBUG".equalsIgnoreCase(System.getProperty("picocli.trace"))) {
ex.printStackTrace(System.err); // show more detail if requested by user
}
return cmd.getExitCodeExceptionMapper() != null
? cmd.getExitCodeExceptionMapper().getExitCode(ex)
: spec.exitCodeOnInvalidInput();
Expand Down
8 changes: 6 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4050,13 +4050,17 @@ <h4 id="_invalid_user_input">9.8.1. Invalid User Input</h4>
CommandLine cmd = ex.getCommandLine();
<span class="predefined-type">PrintWriter</span> writer = cmd.getErr();

writer.println(ex.getMessage());
writer.println(cmd.getColorScheme().errorText(ex.getMessage())); <span class="comment">// bold red</span>
UnmatchedArgumentException.printSuggestions(ex, writer);
writer.print(cmd.getHelp().fullSynopsis()); <span class="comment">// since 4.1</span>
writer.print(cmd.getHelp().fullSynopsis());

CommandSpec spec = cmd.getCommandSpec();
writer.printf(<span class="string"><span class="delimiter">&quot;</span><span class="content">Try '%s --help' for more information.%n</span><span class="delimiter">&quot;</span></span>, spec.qualifiedName());

<span class="keyword">if</span> (<span class="string"><span class="delimiter">&quot;</span><span class="content">DEBUG</span><span class="delimiter">&quot;</span></span>.equalsIgnoreCase(<span class="predefined-type">System</span>.getProperty(<span class="string"><span class="delimiter">&quot;</span><span class="content">picocli.trace</span><span class="delimiter">&quot;</span></span>))) {
ex.printStackTrace(<span class="predefined-type">System</span>.err); <span class="comment">// show more detail if requested by user</span>
}

<span class="keyword">return</span> cmd.getExitCodeExceptionMapper() != <span class="predefined-constant">null</span>
? cmd.getExitCodeExceptionMapper().getExitCode(ex)
: spec.exitCodeOnInvalidInput();
Expand Down

0 comments on commit 1bae8a8

Please sign in to comment.