11package net .jbock .contrib ;
22
33import net .jbock .model .CommandModel ;
4- import net .jbock .util .HasMessage ;
54import net .jbock .util .ParsingFailed ;
65
76import java .io .PrintStream ;
109import java .util .Map ;
1110
1211/**
13- * This class is responsible for standard error handling,
14- * like printing messages and shutting down the JVM .
12+ * A convenience class that performs standard error handling,
13+ * like printing error messages and printing the usage documentation .
1514 */
1615public final class StandardErrorHandler {
1716
@@ -87,10 +86,9 @@ public Builder withMessages(Map<String, String> map) {
8786 }
8887
8988 /**
90- * Set the value of the ansi attribute.
89+ * Sets the value of the ansi attribute.
9190 *
9291 * @param ansi if ansi codes should be used
93- * when printing the usage documentation
9492 * @return the builder instance
9593 */
9694 public Builder withAnsi (boolean ansi ) {
@@ -99,7 +97,7 @@ public Builder withAnsi(boolean ansi) {
9997 }
10098
10199 /**
102- * Create the error handler.
100+ * Creates the error handler.
103101 *
104102 * @return an error handler
105103 */
@@ -117,26 +115,31 @@ public static Builder builder() {
117115 return new Builder ();
118116 }
119117
120- public void printHelp (CommandModel model ) {
118+ /**
119+ * Prints the usage documentation.
120+ *
121+ * @param model command model
122+ */
123+ public void printUsageDocumentation (CommandModel model ) {
121124 UsageDocumentation .builder (model )
122125 .withOutputStream (out )
123126 .withAnsi (ansi )
124127 .withMessages (messages )
125128 .withTerminalWidth (terminalWidth )
126- .build ().printUsageDocumentation ();
129+ .build ()
130+ .printUsageDocumentation ();
127131 out .flush ();
128132 }
129133
130134 /**
131- * This method does standard error handling like printing
132- * error messages, or printing usage documentation.
135+ * Prints an error message.
133136 *
134- * @param parsingFailed an object describing the error condition
137+ * @param failure an object describing the error condition
135138 */
136- public void handle (ParsingFailed parsingFailed ) {
137- CommandModel model = parsingFailed .commandModel ();
139+ public void printErrorMessage (ParsingFailed failure ) {
140+ CommandModel model = failure .commandModel ();
138141 AnsiStyle ansiStyle = AnsiStyle .create (ansi );
139- out .println (ansiStyle .red ("ERROR:" ) + ' ' + (( HasMessage ) parsingFailed ) .message ());
142+ out .println (ansiStyle .red ("ERROR:" ) + ' ' + failure .message ());
140143 List <String > synopsis = Synopsis .create (model )
141144 .createSynopsis ("Usage:" );
142145 out .println (String .join (" " , synopsis ));
0 commit comments