Rename resource bundles and name resources after options/parameters

This commit is contained in:
Paul Schaub 2022-08-04 12:15:53 +02:00
parent 7de94f1815
commit dc5f11469f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
56 changed files with 229 additions and 269 deletions

View file

@ -26,7 +26,7 @@ import java.util.ResourceBundle;
@CommandLine.Command(
name = "sop",
resourceBundle = "sop",
resourceBundle = "msg_sop",
exitCodeOnInvalidInput = 69,
subcommands = {
CommandLine.HelpCommand.class,
@ -48,7 +48,7 @@ import java.util.ResourceBundle;
public class SopCLI {
// Singleton
static SOP SOP_INSTANCE;
static ResourceBundle cliMsg = ResourceBundle.getBundle("sop");
static ResourceBundle cliMsg = ResourceBundle.getBundle("msg_sop");
public static String EXECUTABLE_NAME = "sop";
@ -65,13 +65,13 @@ public class SopCLI {
new CommandLine(new InitLocale()).parseArgs(args);
// get error message bundle
cliMsg = ResourceBundle.getBundle("sop");
cliMsg = ResourceBundle.getBundle("msg_sop");
// Prepare CLI
CommandLine cmd = new CommandLine(SopCLI.class);
// explicitly set help command resource bundle
cmd.getSubcommands().get("help").setResourceBundle(ResourceBundle.getBundle("help"));
cmd.getSubcommands().get("help").setResourceBundle(ResourceBundle.getBundle("msg_help"));
// Hide generate-completion command
cmd.getSubcommands().get("generate-completion").getCommandSpec().usageMessage().hidden(true);

View file

@ -48,7 +48,7 @@ public abstract class AbstractSopCmd implements Runnable {
}
public AbstractSopCmd(@Nonnull Locale locale) {
messages = ResourceBundle.getBundle("sop", locale);
messages = ResourceBundle.getBundle("msg_sop", locale);
}
void throwIfOutputExists(String output) {

View file

@ -14,12 +14,11 @@ import sop.operation.Armor;
import java.io.IOException;
@CommandLine.Command(name = "armor",
resourceBundle = "armor",
resourceBundle = "msg_armor",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class ArmorCmd extends AbstractSopCmd {
@CommandLine.Option(names = {"--label"},
descriptionKey = "usage.option.label",
paramLabel = "{auto|sig|key|cert|message}")
ArmorLabel label;

View file

@ -12,7 +12,7 @@ import sop.operation.Dearmor;
import java.io.IOException;
@CommandLine.Command(name = "dearmor",
resourceBundle = "dearmor",
resourceBundle = "msg_dearmor",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class DearmorCmd extends AbstractSopCmd {

View file

@ -24,7 +24,7 @@ import java.util.List;
import java.util.regex.Pattern;
@CommandLine.Command(name = "decrypt",
resourceBundle = "decrypt",
resourceBundle = "msg_decrypt",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class DecryptCmd extends AbstractSopCmd {
@ -40,50 +40,41 @@ public class DecryptCmd extends AbstractSopCmd {
@CommandLine.Option(
names = {OPT_SESSION_KEY_OUT},
descriptionKey = "usage.option.session_key_out",
paramLabel = "SESSIONKEY")
String sessionKeyOut;
@CommandLine.Option(
names = {OPT_WITH_SESSION_KEY},
descriptionKey = "usage.option.with_session_key",
paramLabel = "SESSIONKEY")
List<String> withSessionKey = new ArrayList<>();
@CommandLine.Option(
names = {OPT_WITH_PASSWORD},
descriptionKey = "usage.option.with_password",
paramLabel = "PASSWORD")
List<String> withPassword = new ArrayList<>();
@CommandLine.Option(names = {OPT_VERIFY_OUT},
descriptionKey = "usage.option.verify_out",
paramLabel = "VERIFICATIONS")
String verifyOut;
@CommandLine.Option(names = {OPT_VERIFY_WITH},
descriptionKey = "usage.option.certs",
paramLabel = "CERT")
List<String> certs = new ArrayList<>();
@CommandLine.Option(names = {OPT_NOT_BEFORE},
descriptionKey = "usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";
@CommandLine.Option(names = {OPT_NOT_AFTER},
descriptionKey = "usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";
@CommandLine.Parameters(index = "0..*",
descriptionKey = "usage.param.keys",
paramLabel = "KEY")
List<String> keys = new ArrayList<>();
@CommandLine.Option(names = {OPT_WITH_KEY_PASSWORD},
descriptionKey = "usage.option.with_key_password",
paramLabel = "PASSWORD")
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();
@Override

View file

@ -17,37 +17,31 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "encrypt",
resourceBundle = "encrypt",
resourceBundle = "msg_encrypt",
exitCodeOnInvalidInput = 37)
public class EncryptCmd extends AbstractSopCmd {
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;
@CommandLine.Option(names = {"--as"},
descriptionKey = "usage.option.type",
paramLabel = "{binary|text}")
EncryptAs type;
@CommandLine.Option(names = "--with-password",
descriptionKey = "usage.option.with_password",
paramLabel = "PASSWORD")
List<String> withPassword = new ArrayList<>();
@CommandLine.Option(names = "--sign-with",
descriptionKey = "usage.option.sign_with",
paramLabel = "KEY")
List<String> signWith = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password",
descriptionKey = "usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();
@CommandLine.Parameters(descriptionKey = "usage.param.certs",
index = "0..*",
@CommandLine.Parameters(index = "0..*",
paramLabel = "CERTS")
List<String> certs = new ArrayList<>();

View file

@ -13,12 +13,11 @@ import sop.exception.SOPGPException;
import sop.operation.ExtractCert;
@CommandLine.Command(name = "extract-cert",
resourceBundle = "extract-cert",
resourceBundle = "msg_extract-cert",
exitCodeOnInvalidInput = 37)
public class ExtractCertCmd extends AbstractSopCmd {
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;

View file

@ -15,20 +15,18 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "generate-key",
resourceBundle = "generate-key",
resourceBundle = "msg_generate-key",
exitCodeOnInvalidInput = 37)
public class GenerateKeyCmd extends AbstractSopCmd {
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;
@CommandLine.Parameters(descriptionKey = "usage.option.user_id")
@CommandLine.Parameters
List<String> userId = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password",
descriptionKey = "usage.option.with_key_password",
paramLabel = "PASSWORD")
String withKeyPassword;

View file

@ -14,18 +14,16 @@ import java.io.IOException;
import java.io.OutputStream;
@CommandLine.Command(name = "inline-detach",
resourceBundle = "inline-detach",
resourceBundle = "msg_inline-detach",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class InlineDetachCmd extends AbstractSopCmd {
@CommandLine.Option(
names = {"--signatures-out"},
descriptionKey = "usage.option.signatures_out",
paramLabel = "SIGNATURES")
String signaturesOut;
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;

View file

@ -17,26 +17,22 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "inline-sign",
resourceBundle = "inline-sign",
resourceBundle = "msg_inline-sign",
exitCodeOnInvalidInput = 37)
public class InlineSignCmd extends AbstractSopCmd {
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;
@CommandLine.Option(names = "--as",
descriptionKey = "usage.option.as",
paramLabel = "{binary|text|cleartextsigned}")
InlineSignAs type;
@CommandLine.Parameters(descriptionKey = "usage.parameter.keys",
paramLabel = "KEYS")
@CommandLine.Parameters(paramLabel = "KEYS")
List<String> secretKeyFile = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password",
descriptionKey = "usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();

View file

@ -19,27 +19,23 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "inline-verify",
resourceBundle = "inline-verify",
resourceBundle = "msg_inline-verify",
exitCodeOnInvalidInput = 37)
public class InlineVerifyCmd extends AbstractSopCmd {
@CommandLine.Parameters(arity = "1..*",
descriptionKey = "usage.parameter.certs",
paramLabel = "CERT")
List<String> certificates = new ArrayList<>();
@CommandLine.Option(names = {"--not-before"},
descriptionKey = "usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";
@CommandLine.Option(names = {"--not-after"},
descriptionKey = "usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";
@CommandLine.Option(names = "--verifications-out",
descriptionKey = "usage.option.verifications_out")
@CommandLine.Option(names = "--verifications-out")
String verificationsOut;
@Override

View file

@ -20,31 +20,26 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "sign",
resourceBundle = "detached-sign",
resourceBundle = "msg_detached-sign",
exitCodeOnInvalidInput = 37)
public class SignCmd extends AbstractSopCmd {
@CommandLine.Option(names = "--no-armor",
descriptionKey = "usage.option.armor",
negatable = true)
boolean armor = true;
@CommandLine.Option(names = "--as",
descriptionKey = "usage.option.as",
paramLabel = "{binary|text}")
SignAs type;
@CommandLine.Parameters(descriptionKey = "usage.parameter.keys",
paramLabel = "KEYS")
@CommandLine.Parameters(paramLabel = "KEYS")
List<String> secretKeyFile = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password",
descriptionKey = "usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();
@CommandLine.Option(names = "--micalg-out",
descriptionKey = "usage.option.micalg_out",
paramLabel = "MICALG")
String micAlgOut;

View file

@ -17,28 +17,24 @@ import java.util.ArrayList;
import java.util.List;
@CommandLine.Command(name = "verify",
resourceBundle = "detached-verify",
resourceBundle = "msg_detached-verify",
exitCodeOnInvalidInput = 37)
public class VerifyCmd extends AbstractSopCmd {
@CommandLine.Parameters(index = "0",
descriptionKey = "usage.parameter.signature",
paramLabel = "SIGNATURE")
String signature;
@CommandLine.Parameters(index = "0..*",
arity = "1..*",
descriptionKey = "usage.parameter.certs",
paramLabel = "CERT")
List<String> certificates = new ArrayList<>();
@CommandLine.Option(names = {"--not-before"},
descriptionKey = "usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";
@CommandLine.Option(names = {"--not-after"},
descriptionKey = "usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";

View file

@ -9,7 +9,7 @@ import sop.cli.picocli.Print;
import sop.cli.picocli.SopCLI;
import sop.operation.Version;
@CommandLine.Command(name = "version", resourceBundle = "version",
@CommandLine.Command(name = "version", resourceBundle = "msg_version",
exitCodeOnInvalidInput = 37)
public class VersionCmd extends AbstractSopCmd {
@ -17,12 +17,10 @@ public class VersionCmd extends AbstractSopCmd {
Exclusive exclusive;
static class Exclusive {
@CommandLine.Option(names = "--extended",
descriptionKey = "usage.option.extended")
@CommandLine.Option(names = "--extended")
boolean extended;
@CommandLine.Option(names = "--backend",
descriptionKey = "usage.option.backend")
@CommandLine.Option(names = "--backend")
boolean backend;
}