mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-13 19:42:06 +01:00
33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package sop.cli.picocli;
|
|
|
|
import picocli.CommandLine;
|
|
|
|
public class SOPExecutionExceptionHandler implements CommandLine.IExecutionExceptionHandler {
|
|
|
|
@Override
|
|
public int handleExecutionException(Exception ex, CommandLine commandLine, CommandLine.ParseResult parseResult) {
|
|
|
|
int exitCode = commandLine.getExitCodeExceptionMapper() != null ?
|
|
commandLine.getExitCodeExceptionMapper().getExitCode(ex) :
|
|
commandLine.getCommandSpec().exitCodeOnExecutionException();
|
|
|
|
CommandLine.Help.ColorScheme colorScheme = commandLine.getColorScheme();
|
|
// CHECKSTYLE:OFF
|
|
if (ex.getMessage() != null) {
|
|
commandLine.getErr().println(colorScheme.errorText(ex.getMessage()));
|
|
} else {
|
|
commandLine.getErr().println(ex.getClass().getName());
|
|
}
|
|
|
|
if (SopCLI.stacktrace) {
|
|
ex.printStackTrace(commandLine.getErr());
|
|
}
|
|
// CHECKSTYLE:ON
|
|
|
|
return exitCode;
|
|
}
|
|
}
|