2022-01-11 13:46:05 +01:00
|
|
|
// 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;
|
2022-05-24 21:19:37 +02:00
|
|
|
import sop.operation.InlineDetach;
|
2022-01-11 13:46:05 +01:00
|
|
|
|
2022-06-06 20:06:14 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
2022-05-29 21:17:03 +02:00
|
|
|
@CommandLine.Command(name = "inline-detach",
|
2022-08-04 12:15:53 +02:00
|
|
|
resourceBundle = "msg_inline-detach",
|
2022-01-11 13:46:05 +01:00
|
|
|
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
2022-05-29 21:17:03 +02:00
|
|
|
public class InlineDetachCmd extends AbstractSopCmd {
|
2022-01-11 13:46:05 +01:00
|
|
|
|
|
|
|
@CommandLine.Option(
|
|
|
|
names = {"--signatures-out"},
|
|
|
|
paramLabel = "SIGNATURES")
|
2022-06-06 20:06:14 +02:00
|
|
|
String signaturesOut;
|
2022-01-11 13:46:05 +01:00
|
|
|
|
|
|
|
@CommandLine.Option(names = "--no-armor",
|
|
|
|
negatable = true)
|
|
|
|
boolean armor = true;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2022-05-29 21:17:03 +02:00
|
|
|
InlineDetach inlineDetach = throwIfUnsupportedSubcommand(
|
|
|
|
SopCLI.getSop().inlineDetach(), "inline-detach");
|
2022-01-11 13:46:05 +01:00
|
|
|
|
2022-06-06 20:06:14 +02:00
|
|
|
throwIfOutputExists(signaturesOut);
|
2022-05-29 21:17:03 +02:00
|
|
|
throwIfMissingArg(signaturesOut, "--signatures-out");
|
2022-01-11 13:46:05 +01:00
|
|
|
|
|
|
|
if (!armor) {
|
2022-05-29 21:17:03 +02:00
|
|
|
inlineDetach.noArmor();
|
2022-01-11 13:46:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 20:06:14 +02:00
|
|
|
try (OutputStream outputStream = getOutput(signaturesOut)) {
|
2022-05-29 21:17:03 +02:00
|
|
|
Signatures signatures = inlineDetach
|
2022-01-11 13:46:05 +01:00
|
|
|
.message(System.in).writeTo(System.out);
|
2022-06-06 20:06:14 +02:00
|
|
|
signatures.writeTo(outputStream);
|
2022-01-11 13:46:05 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|