2022-04-06 16:17:57 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package pgp.vks.client.cli;
|
|
|
|
|
|
|
|
import pgp.vks.client.VKS;
|
|
|
|
import pgp.vks.client.VKSImpl;
|
|
|
|
import picocli.CommandLine;
|
|
|
|
|
|
|
|
import java.net.MalformedURLException;
|
2022-08-04 00:49:08 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.ResourceBundle;
|
2022-04-06 16:17:57 +02:00
|
|
|
|
|
|
|
@CommandLine.Command(
|
2022-04-11 13:54:24 +02:00
|
|
|
name = "vks",
|
2022-08-04 00:49:08 +02:00
|
|
|
resourceBundle = "msg_vks",
|
2022-04-06 16:17:57 +02:00
|
|
|
subcommands = {
|
|
|
|
CommandLine.HelpCommand.class,
|
|
|
|
GetCmd.class,
|
|
|
|
UploadCmd.class,
|
|
|
|
RequestVerificationCmd.class
|
|
|
|
}
|
|
|
|
)
|
|
|
|
public class VKSCLI {
|
|
|
|
|
2022-04-23 02:02:34 +02:00
|
|
|
String keyServer = "https://keys.openpgp.org";
|
2022-04-06 16:17:57 +02:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
int exitCode = execute(args);
|
|
|
|
if (exitCode != 0) {
|
|
|
|
System.exit(exitCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int execute(String[] args) {
|
2022-08-04 00:49:08 +02:00
|
|
|
CommandLine cmd = new CommandLine(VKSCLI.class);
|
|
|
|
cmd.setExitCodeExceptionMapper(new CommandLine.IExitCodeExceptionMapper() {
|
2022-04-06 16:17:57 +02:00
|
|
|
@Override
|
|
|
|
public int getExitCode(Throwable exception) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-04 00:49:08 +02:00
|
|
|
});
|
|
|
|
cmd.getSubcommands().get("help").setResourceBundle(ResourceBundle.getBundle("msg_help", Locale.getDefault()));
|
|
|
|
return cmd.setCommandName("vkscli")
|
2022-04-06 16:17:57 +02:00
|
|
|
.execute(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public VKS getApi() throws MalformedURLException {
|
|
|
|
return new VKSImpl(keyServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class KeyServerMixin {
|
|
|
|
|
|
|
|
@CommandLine.ParentCommand
|
|
|
|
VKSCLI parent;
|
|
|
|
|
|
|
|
@CommandLine.Option(names = "--key-server",
|
|
|
|
paramLabel = "KEYSERVER")
|
|
|
|
public void setKeyServer(String keyServer) {
|
|
|
|
parent.keyServer = keyServer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|