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

sop.cli.picocli.commands.ExtractCertCmd.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.commands

import java.io.IOException
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import sop.cli.picocli.SopCLI
import sop.exception.SOPGPException
import sop.exception.SOPGPException.BadData

@Command(
    name = "extract-cert",
    resourceBundle = "msg_extract-cert",
    exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
class ExtractCertCmd : AbstractSopCmd() {

    @Option(names = ["--no-armor"], negatable = true) var armor = true

    override fun run() {
        val extractCert =
            throwIfUnsupportedSubcommand(SopCLI.getSop().extractCert(), "extract-cert")

        if (!armor) {
            extractCert.noArmor()
        }

        try {
            val ready = extractCert.key(System.`in`)
            ready.writeTo(System.out)
        } catch (e: IOException) {
            throw RuntimeException(e)
        } catch (badData: BadData) {
            val errorMsg = getMsg("sop.error.input.stdin_not_a_private_key")
            throw BadData(errorMsg, badData)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy