Catch option error during execution too, since OptionSet is passed there
This commit is contained in:
parent
209da28bb2
commit
8321d7c5c2
|
@ -56,7 +56,7 @@ public abstract class Command {
|
||||||
options = parser.parse(args);
|
options = parser.parse(args);
|
||||||
} catch (OptionException e) {
|
} catch (OptionException e) {
|
||||||
printHelp(terminal);
|
printHelp(terminal);
|
||||||
terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
|
terminal.println("ERROR: " + e.getMessage());
|
||||||
return ExitCodes.USAGE;
|
return ExitCodes.USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public abstract class Command {
|
||||||
if (options.has(verboseOption)) {
|
if (options.has(verboseOption)) {
|
||||||
// mutually exclusive, we can remove this with jopt-simple 5.0, which natively supports it
|
// mutually exclusive, we can remove this with jopt-simple 5.0, which natively supports it
|
||||||
printHelp(terminal);
|
printHelp(terminal);
|
||||||
terminal.println(Terminal.Verbosity.SILENT, "ERROR: Cannot specify -s and -v together");
|
terminal.println("ERROR: Cannot specify -s and -v together");
|
||||||
return ExitCodes.USAGE;
|
return ExitCodes.USAGE;
|
||||||
}
|
}
|
||||||
terminal.setVerbosity(Terminal.Verbosity.SILENT);
|
terminal.setVerbosity(Terminal.Verbosity.SILENT);
|
||||||
|
@ -81,6 +81,10 @@ public abstract class Command {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return execute(terminal, options);
|
return execute(terminal, options);
|
||||||
|
} catch (OptionException e) {
|
||||||
|
printHelp(terminal);
|
||||||
|
terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
|
||||||
|
return ExitCodes.USAGE;
|
||||||
} catch (UserError e) {
|
} catch (UserError e) {
|
||||||
terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
|
terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
|
||||||
return e.exitCode;
|
return e.exitCode;
|
||||||
|
|
Loading…
Reference in New Issue