Package io.github.qishr.cascara.common.util
Interface IExitCodeExceptionMapper
java.lang.Object
io.github.qishr.cascara.common.util.CommandLine.IExitCodeExceptionMapper
Enclosing Class:
io.github.qishr.cascara.common.util.CommandLine
public static interface IExitCodeExceptionMapper
Interface that provides the appropriate exit code that will be returned from the #execute(String...) method for an exception that occurred during parsing or while invoking the command's Runnable, Callable, or Method.
Example usage:
Command class FailingCommand implements CallableVoid { public Void call() throws IOException { throw new IOException("error"); } } IExitCodeExceptionMapper mapper = new IExitCodeExceptionMapper() { public int getExitCode(Throwable t) { if (t instanceof IOException "error".equals(t.getMessage())) { return 123; } return 987; } }
CommandLine cmd = new CommandLine(new FailingCommand()); cmd.setExitCodeExceptionMapper(mapper); int exitCode = cmd.execute(args); assert exitCode == 123; System.exit(exitCode);
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public abstract int | getExitCode(Throwable exception) | Returns the exit code that should be returned from the #execute(String...) method. |
Method Details
getExitCode
public abstract int getExitCode(Throwable exception)
Returns the exit code that should be returned from the #execute(String...) method.
Parameters:
exception - the exception that occurred during parsing or while invoking the command's Runnable, Callable, or Method.
Returns:
the exit code