mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-19 05:52:04 +01:00
Kotlin conversion: InlineDetachCmd
This commit is contained in:
parent
9daabb758a
commit
714c933cef
2 changed files with 47 additions and 50 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue