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

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

// SPDX-FileCopyrightText: 2021 Paul Schaub 
//
// 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;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy