Kotlin conversion: InlineDetachCmd

This commit is contained in:
Paul Schaub 2023-11-04 18:31:52 +01:00
parent 9daabb758a
commit 714c933cef
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
2 changed files with 47 additions and 50 deletions

View File

@ -1,50 +0,0 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.cli.picocli.commands;
import picocli.CommandLine;
import sop.Signatures;
import sop.cli.picocli.SopCLI;
import sop.exception.SOPGPException;
import sop.operation.InlineDetach;
import java.io.IOException;
import java.io.OutputStream;
@CommandLine.Command(name = "inline-detach",
resourceBundle = "msg_inline-detach",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class InlineDetachCmd extends AbstractSopCmd {
@CommandLine.Option(
names = {"--signatures-out"},
paramLabel = "SIGNATURES")
String signaturesOut;
@CommandLine.Option(names = "--no-armor",
negatable = true)
boolean armor = true;
@Override
public void run() {
InlineDetach inlineDetach = throwIfUnsupportedSubcommand(
SopCLI.getSop().inlineDetach(), "inline-detach");
throwIfOutputExists(signaturesOut);
throwIfMissingArg(signaturesOut, "--signatures-out");
if (!armor) {
inlineDetach.noArmor();
}
try (OutputStream outputStream = getOutput(signaturesOut)) {
Signatures signatures = inlineDetach
.message(System.in).writeTo(System.out);
signatures.writeTo(outputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.cli.picocli.commands
import java.io.IOException
import java.lang.RuntimeException
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import sop.cli.picocli.SopCLI
import sop.exception.SOPGPException
@Command(
name = "inline-detach",
resourceBundle = "msg_inline-detach",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
class InlineDetachCmd : AbstractSopCmd() {
@Option(names = ["--signatures-out"], paramLabel = "SIGNATURES")
var signaturesOut: String? = null
@Option(names = ["--no-armor"], negatable = true) var armor: Boolean = true
override fun run() {
val inlineDetach =
throwIfUnsupportedSubcommand(SopCLI.getSop().inlineDetach(), "inline-detach")
throwIfOutputExists(signaturesOut)
throwIfMissingArg(signaturesOut, "--signatures-out")
if (!armor) {
inlineDetach.noArmor()
}
try {
getOutput(signaturesOut).use { sigOut ->
inlineDetach
.message(System.`in`)
.writeTo(System.out) // message out
.writeTo(sigOut) // signatures out
}
} catch (e: IOException) {
throw RuntimeException(e)
}
}
}