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;
|
|
|
|
|
2022-03-11 17:22:52 +01:00
|
|
|
import picocli.AutoComplete;
|
2022-01-11 13:46:05 +01:00
|
|
|
import picocli.CommandLine;
|
|
|
|
import sop.SOP;
|
|
|
|
import sop.cli.picocli.commands.ArmorCmd;
|
|
|
|
import sop.cli.picocli.commands.DearmorCmd;
|
|
|
|
import sop.cli.picocli.commands.DecryptCmd;
|
|
|
|
import sop.cli.picocli.commands.DetachInbandSignatureAndMessageCmd;
|
|
|
|
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 = {
|
|
|
|
CommandLine.HelpCommand.class,
|
|
|
|
ArmorCmd.class,
|
|
|
|
DearmorCmd.class,
|
|
|
|
DecryptCmd.class,
|
|
|
|
DetachInbandSignatureAndMessageCmd.class,
|
|
|
|
EncryptCmd.class,
|
|
|
|
ExtractCertCmd.class,
|
|
|
|
GenerateKeyCmd.class,
|
|
|
|
SignCmd.class,
|
|
|
|
VerifyCmd.class,
|
2022-03-11 17:22:52 +01:00
|
|
|
VersionCmd.class,
|
|
|
|
AutoComplete.GenerateCompletion.class
|
2022-01-11 13:46:05 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
public class SopCLI {
|
|
|
|
// Singleton
|
|
|
|
static SOP SOP_INSTANCE;
|
|
|
|
|
|
|
|
public static String EXECUTABLE_NAME = "sop";
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
int exitCode = execute(args);
|
|
|
|
if (exitCode != 0) {
|
|
|
|
System.exit(exitCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int execute(String[] args) {
|
2022-03-11 17:22:52 +01:00
|
|
|
CommandLine cmd = new CommandLine(SopCLI.class);
|
|
|
|
// Hide generate-completion command
|
|
|
|
CommandLine gen = cmd.getSubcommands().get("generate-completion");
|
|
|
|
gen.getCommandSpec().usageMessage().hidden(true);
|
|
|
|
|
|
|
|
cmd.setCommandName(EXECUTABLE_NAME)
|
2022-01-11 13:46:05 +01:00
|
|
|
.setExecutionExceptionHandler(new SOPExecutionExceptionHandler())
|
|
|
|
.setExitCodeExceptionMapper(new SOPExceptionExitCodeMapper())
|
2022-03-11 17:22:52 +01:00
|
|
|
.setCaseInsensitiveEnumValuesAllowed(true);
|
|
|
|
|
|
|
|
return cmd.execute(args);
|
2022-01-11 13:46:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|