2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
package sop.cli.picocli;
|
|
|
|
|
|
|
|
import picocli.CommandLine;
|
|
|
|
import sop.SOP;
|
|
|
|
import sop.cli.picocli.commands.ArmorCmd;
|
|
|
|
import sop.cli.picocli.commands.DearmorCmd;
|
|
|
|
import sop.cli.picocli.commands.DecryptCmd;
|
2021-08-18 18:27:22 +02:00
|
|
|
import sop.cli.picocli.commands.DetachInbandSignatureAndMessageCmd;
|
2021-07-15 16:55:13 +02:00
|
|
|
import sop.cli.picocli.commands.EncryptCmd;
|
|
|
|
import sop.cli.picocli.commands.ExtractCertCmd;
|
|
|
|
import sop.cli.picocli.commands.GenerateKeyCmd;
|
|
|
|
import sop.cli.picocli.commands.SignCmd;
|
|
|
|
import sop.cli.picocli.commands.VerifyCmd;
|
|
|
|
import sop.cli.picocli.commands.VersionCmd;
|
|
|
|
|
|
|
|
@CommandLine.Command(
|
|
|
|
exitCodeOnInvalidInput = 69,
|
|
|
|
subcommands = {
|
2021-07-15 17:49:30 +02:00
|
|
|
CommandLine.HelpCommand.class,
|
2021-07-15 16:55:13 +02:00
|
|
|
ArmorCmd.class,
|
|
|
|
DearmorCmd.class,
|
|
|
|
DecryptCmd.class,
|
2021-08-18 18:27:22 +02:00
|
|
|
DetachInbandSignatureAndMessageCmd.class,
|
2021-07-15 16:55:13 +02:00
|
|
|
EncryptCmd.class,
|
|
|
|
ExtractCertCmd.class,
|
|
|
|
GenerateKeyCmd.class,
|
|
|
|
SignCmd.class,
|
|
|
|
VerifyCmd.class,
|
|
|
|
VersionCmd.class
|
|
|
|
}
|
|
|
|
)
|
|
|
|
public class SopCLI {
|
2021-07-23 21:02:36 +02:00
|
|
|
// Singleton
|
2021-07-15 16:55:13 +02:00
|
|
|
static SOP SOP_INSTANCE;
|
|
|
|
|
2021-07-23 21:02:36 +02:00
|
|
|
public static String EXECUTABLE_NAME = "sop";
|
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
public static void main(String[] args) {
|
|
|
|
int exitCode = execute(args);
|
|
|
|
if (exitCode != 0) {
|
|
|
|
System.exit(exitCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int execute(String[] args) {
|
|
|
|
return new CommandLine(SopCLI.class)
|
2021-07-23 21:02:36 +02:00
|
|
|
.setCommandName(EXECUTABLE_NAME)
|
2021-07-19 18:20:52 +02:00
|
|
|
.setExecutionExceptionHandler(new SOPExecutionExceptionHandler())
|
|
|
|
.setExitCodeExceptionMapper(new SOPExceptionExitCodeMapper())
|
2021-07-15 16:55:13 +02:00
|
|
|
.setCaseInsensitiveEnumValuesAllowed(true)
|
|
|
|
.execute(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SOP getSop() {
|
|
|
|
if (SOP_INSTANCE == null) {
|
|
|
|
throw new IllegalStateException("No SOP backend set.");
|
|
|
|
}
|
|
|
|
return SOP_INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSopInstance(SOP instance) {
|
|
|
|
SOP_INSTANCE = instance;
|
|
|
|
}
|
|
|
|
}
|