2022-02-21 11:51:30 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package pgp.wkd.cli;
|
|
|
|
|
2022-03-21 11:25:03 +01:00
|
|
|
import pgp.wkd.exception.CertNotFetchableException;
|
|
|
|
import pgp.wkd.exception.RejectedCertificateException;
|
2022-04-11 13:47:41 +02:00
|
|
|
import pgp.wkd.cli.command.GetCmd;
|
2022-02-21 14:16:55 +01:00
|
|
|
import picocli.CommandLine;
|
|
|
|
|
|
|
|
@CommandLine.Command(
|
2022-04-11 13:47:41 +02:00
|
|
|
name = "wkd",
|
2022-08-04 13:26:22 +02:00
|
|
|
resourceBundle = "msg_wkd",
|
2022-02-21 14:16:55 +01:00
|
|
|
subcommands = {
|
|
|
|
CommandLine.HelpCommand.class,
|
2022-04-11 13:47:41 +02:00
|
|
|
GetCmd.class
|
2022-02-21 14:16:55 +01:00
|
|
|
}
|
|
|
|
)
|
2022-02-21 11:51:30 +01:00
|
|
|
public class WKDCLI {
|
|
|
|
|
2022-02-21 14:16:55 +01: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(WKDCLI.class)
|
2022-03-02 18:01:12 +01:00
|
|
|
.setExitCodeExceptionMapper(new CommandLine.IExitCodeExceptionMapper() {
|
|
|
|
@Override
|
|
|
|
public int getExitCode(Throwable exception) {
|
2022-03-21 11:25:03 +01:00
|
|
|
if (exception instanceof RejectedCertificateException) {
|
|
|
|
return ((RejectedCertificateException) exception).getErrorCode();
|
2022-03-02 18:01:12 +01:00
|
|
|
} else if (exception instanceof CertNotFetchableException) {
|
|
|
|
return CertNotFetchableException.ERROR_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Others get mapped to 1
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
})
|
2022-02-21 14:16:55 +01:00
|
|
|
.setCommandName("wkdcli")
|
|
|
|
.execute(args);
|
|
|
|
}
|
2022-02-21 11:51:30 +01:00
|
|
|
}
|