All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sop.cli.picocli.SOPExecutionExceptionHandler.kt Maven / Gradle / Ivy

There is a newer version: 10.0.3
Show newest version
// SPDX-FileCopyrightText: 2023 Paul Schaub 
//
// 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
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy