mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-09-27 10:39:32 +02:00
35 lines
1 KiB
Kotlin
35 lines
1 KiB
Kotlin
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package sop.cli.picocli
|
|
|
|
import picocli.CommandLine
|
|
import picocli.CommandLine.IExecutionExceptionHandler
|
|
|
|
class SOPExecutionExceptionHandler : IExecutionExceptionHandler {
|
|
override fun handleExecutionException(
|
|
ex: Exception,
|
|
commandLine: CommandLine,
|
|
parseResult: CommandLine.ParseResult
|
|
): Int {
|
|
val exitCode =
|
|
if (commandLine.exitCodeExceptionMapper != null)
|
|
commandLine.exitCodeExceptionMapper.getExitCode(ex)
|
|
else commandLine.commandSpec.exitCodeOnExecutionException()
|
|
|
|
val colorScheme = commandLine.colorScheme
|
|
if (ex.message != null) {
|
|
commandLine.getErr().println(colorScheme.errorText(ex.message))
|
|
} else {
|
|
commandLine.getErr().println(ex.javaClass.getName())
|
|
}
|
|
|
|
if (SopCLI.stacktrace) {
|
|
ex.printStackTrace(commandLine.getErr())
|
|
}
|
|
|
|
return exitCode
|
|
}
|
|
}
|