2021-07-15 16:55:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Paul Schaub.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|