Skip to content

Commit

Permalink
Merge branch 'sharedResource'
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Aug 4, 2022
2 parents d80a0a0 + 0cb6148 commit 092a83a
Show file tree
Hide file tree
Showing 44 changed files with 426 additions and 380 deletions.
17 changes: 11 additions & 6 deletions sop-java-picocli/src/main/java/sop/cli/picocli/SopCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@CommandLine.Command(
name = "sop",
resourceBundle = "sop",
resourceBundle = "msg_sop",
exitCodeOnInvalidInput = 69,
subcommands = {
CommandLine.HelpCommand.class,
Expand All @@ -48,7 +48,7 @@
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";

Expand All @@ -64,15 +64,20 @@ public static int execute(String[] args) {
// Set locale
new CommandLine(new InitLocale()).parseArgs(args);

cliMsg = ResourceBundle.getBundle("sop");
// get error message bundle
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("msg_help"));

// Hide generate-completion command
CommandLine gen = cmd.getSubcommands().get("generate-completion");
gen.getCommandSpec().usageMessage().hidden(true);
cmd.getSubcommands().get("generate-completion").getCommandSpec().usageMessage().hidden(true);

cmd.setExecutionExceptionHandler(new SOPExecutionExceptionHandler())
cmd.setCommandName(EXECUTABLE_NAME)
.setExecutionExceptionHandler(new SOPExecutionExceptionHandler())
.setExitCodeExceptionMapper(new SOPExceptionExitCodeMapper())
.setCaseInsensitiveEnumValuesAllowed(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AbstractSopCmd() {
}

public AbstractSopCmd(@Nonnull Locale locale) {
messages = ResourceBundle.getBundle("sop", locale);
messages = ResourceBundle.getBundle("msg_sop", locale);
}

void throwIfOutputExists(String output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import java.io.IOException;

@CommandLine.Command(name = "armor",
resourceBundle = "sop",
resourceBundle = "msg_armor",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class ArmorCmd extends AbstractSopCmd {

@CommandLine.Option(names = {"--label"},
descriptionKey = "sop.armor.usage.option.label",
paramLabel = "{auto|sig|key|cert|message}")
ArmorLabel label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.IOException;

@CommandLine.Command(name = "dearmor",
resourceBundle = "sop",
resourceBundle = "msg_dearmor",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class DearmorCmd extends AbstractSopCmd {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.regex.Pattern;

@CommandLine.Command(name = "decrypt",
resourceBundle = "sop",
resourceBundle = "msg_decrypt",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class DecryptCmd extends AbstractSopCmd {

Expand All @@ -40,50 +40,41 @@ public class DecryptCmd extends AbstractSopCmd {

@CommandLine.Option(
names = {OPT_SESSION_KEY_OUT},
descriptionKey = "sop.decrypt.usage.option.session_key_out",
paramLabel = "SESSIONKEY")
String sessionKeyOut;

@CommandLine.Option(
names = {OPT_WITH_SESSION_KEY},
descriptionKey = "sop.decrypt.usage.option.with_session_key",
paramLabel = "SESSIONKEY")
List<String> withSessionKey = new ArrayList<>();

@CommandLine.Option(
names = {OPT_WITH_PASSWORD},
descriptionKey = "sop.decrypt.usage.option.with_password",
paramLabel = "PASSWORD")
List<String> withPassword = new ArrayList<>();

@CommandLine.Option(names = {OPT_VERIFY_OUT},
descriptionKey = "sop.decrypt.usage.option.verify_out",
paramLabel = "VERIFICATIONS")
String verifyOut;

@CommandLine.Option(names = {OPT_VERIFY_WITH},
descriptionKey = "sop.decrypt.usage.option.certs",
paramLabel = "CERT")
List<String> certs = new ArrayList<>();

@CommandLine.Option(names = {OPT_NOT_BEFORE},
descriptionKey = "sop.decrypt.usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";

@CommandLine.Option(names = {OPT_NOT_AFTER},
descriptionKey = "sop.decrypt.usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";

@CommandLine.Parameters(index = "0..*",
descriptionKey = "sop.decrypt.usage.param.keys",
paramLabel = "KEY")
List<String> keys = new ArrayList<>();

@CommandLine.Option(names = {OPT_WITH_KEY_PASSWORD},
descriptionKey = "sop.decrypt.usage.option.with_key_password",
paramLabel = "PASSWORD")
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,31 @@
import java.util.List;

@CommandLine.Command(name = "encrypt",
resourceBundle = "sop",
resourceBundle = "msg_encrypt",
exitCodeOnInvalidInput = 37)
public class EncryptCmd extends AbstractSopCmd {

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.encrypt.usage.option.armor",
negatable = true)
boolean armor = true;

@CommandLine.Option(names = {"--as"},
descriptionKey = "sop.encrypt.usage.option.type",
paramLabel = "{binary|text}")
EncryptAs type;

@CommandLine.Option(names = "--with-password",
descriptionKey = "sop.encrypt.usage.option.with_password",
paramLabel = "PASSWORD")
List<String> withPassword = new ArrayList<>();

@CommandLine.Option(names = "--sign-with",
descriptionKey = "sop.encrypt.usage.option.sign_with",
paramLabel = "KEY")
List<String> signWith = new ArrayList<>();

@CommandLine.Option(names = "--with-key-password",
descriptionKey = "sop.encrypt.usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();

@CommandLine.Parameters(descriptionKey = "sop.encrypt.usage.param.certs",
index = "0..*",
@CommandLine.Parameters(index = "0..*",
paramLabel = "CERTS")
List<String> certs = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
import sop.operation.ExtractCert;

@CommandLine.Command(name = "extract-cert",
resourceBundle = "sop",
resourceBundle = "msg_extract-cert",
exitCodeOnInvalidInput = 37)
public class ExtractCertCmd extends AbstractSopCmd {

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.extract-cert.usage.option.armor",
negatable = true)
boolean armor = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
import java.util.List;

@CommandLine.Command(name = "generate-key",
resourceBundle = "sop",
resourceBundle = "msg_generate-key",
exitCodeOnInvalidInput = 37)
public class GenerateKeyCmd extends AbstractSopCmd {

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.generate-key.usage.option.armor",
negatable = true)
boolean armor = true;

@CommandLine.Parameters(descriptionKey = "sop.generate-key.usage.option.user_id")
@CommandLine.Parameters(paramLabel = "USERID")
List<String> userId = new ArrayList<>();

@CommandLine.Option(names = "--with-key-password",
descriptionKey = "sop.generate-key.usage.option.with_key_password",
paramLabel = "PASSWORD")
String withKeyPassword;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
import java.io.OutputStream;

@CommandLine.Command(name = "inline-detach",
resourceBundle = "sop",
resourceBundle = "msg_inline-detach",
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
public class InlineDetachCmd extends AbstractSopCmd {

@CommandLine.Option(
names = {"--signatures-out"},
descriptionKey = "sop.inline-detach.usage.option.signatures_out",
paramLabel = "SIGNATURES")
String signaturesOut;

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.inline-detach.usage.option.armor",
negatable = true)
boolean armor = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@
import java.util.List;

@CommandLine.Command(name = "inline-sign",
resourceBundle = "sop",
resourceBundle = "msg_inline-sign",
exitCodeOnInvalidInput = 37)
public class InlineSignCmd extends AbstractSopCmd {

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.inline-sign.usage.option.armor",
negatable = true)
boolean armor = true;

@CommandLine.Option(names = "--as",
descriptionKey = "sop.inline-sign.usage.option.as",
paramLabel = "{binary|text|cleartextsigned}")
InlineSignAs type;

@CommandLine.Parameters(descriptionKey = "sop.inline-sign.usage.parameter.keys",
paramLabel = "KEYS")
@CommandLine.Parameters(paramLabel = "KEYS")
List<String> secretKeyFile = new ArrayList<>();

@CommandLine.Option(names = "--with-key-password",
descriptionKey = "sop.inline-sign.usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,23 @@
import java.util.List;

@CommandLine.Command(name = "inline-verify",
resourceBundle = "sop",
resourceBundle = "msg_inline-verify",
exitCodeOnInvalidInput = 37)
public class InlineVerifyCmd extends AbstractSopCmd {

@CommandLine.Parameters(arity = "1..*",
descriptionKey = "sop.inline-verify.usage.parameter.certs",
paramLabel = "CERT")
List<String> certificates = new ArrayList<>();

@CommandLine.Option(names = {"--not-before"},
descriptionKey = "sop.inline-verify.usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";

@CommandLine.Option(names = {"--not-after"},
descriptionKey = "sop.inline-verify.usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";

@CommandLine.Option(names = "--verifications-out",
descriptionKey = "sop.inline-verify.usage.option.verifications_out")
@CommandLine.Option(names = "--verifications-out")
String verificationsOut;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,26 @@
import java.util.List;

@CommandLine.Command(name = "sign",
resourceBundle = "sop",
resourceBundle = "msg_detached-sign",
exitCodeOnInvalidInput = 37)
public class SignCmd extends AbstractSopCmd {

@CommandLine.Option(names = "--no-armor",
descriptionKey = "sop.sign.usage.option.armor",
negatable = true)
boolean armor = true;

@CommandLine.Option(names = "--as",
descriptionKey = "sop.sign.usage.option.as",
paramLabel = "{binary|text}")
SignAs type;

@CommandLine.Parameters(descriptionKey = "sop.sign.usage.parameter.keys",
paramLabel = "KEYS")
@CommandLine.Parameters(paramLabel = "KEYS")
List<String> secretKeyFile = new ArrayList<>();

@CommandLine.Option(names = "--with-key-password",
descriptionKey = "sop.sign.usage.option.with_key_password",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();

@CommandLine.Option(names = "--micalg-out",
descriptionKey = "sop.sign.usage.option.micalg_out",
paramLabel = "MICALG")
String micAlgOut;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@
import java.util.List;

@CommandLine.Command(name = "verify",
resourceBundle = "sop",
resourceBundle = "msg_detached-verify",
exitCodeOnInvalidInput = 37)
public class VerifyCmd extends AbstractSopCmd {

@CommandLine.Parameters(index = "0",
descriptionKey = "sop.verify.usage.parameter.signature",
paramLabel = "SIGNATURE")
String signature;

@CommandLine.Parameters(index = "0..*",
arity = "1..*",
descriptionKey = "sop.verify.usage.parameter.certs",
paramLabel = "CERT")
List<String> certificates = new ArrayList<>();

@CommandLine.Option(names = {"--not-before"},
descriptionKey = "sop.verify.usage.option.not_before",
paramLabel = "DATE")
String notBefore = "-";

@CommandLine.Option(names = {"--not-after"},
descriptionKey = "sop.verify.usage.option.not_after",
paramLabel = "DATE")
String notAfter = "now";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
import sop.cli.picocli.SopCLI;
import sop.operation.Version;

@CommandLine.Command(name = "version", resourceBundle = "sop",
@CommandLine.Command(name = "version", resourceBundle = "msg_version",
exitCodeOnInvalidInput = 37)
public class VersionCmd extends AbstractSopCmd {

@CommandLine.ArgGroup()
Exclusive exclusive;

static class Exclusive {
@CommandLine.Option(names = "--extended",
descriptionKey = "sop.version.usage.option.extended")
@CommandLine.Option(names = "--extended")
boolean extended;

@CommandLine.Option(names = "--backend",
descriptionKey = "sop.version.usage.option.backend")
@CommandLine.Option(names = "--backend")
boolean backend;
}

Expand Down
5 changes: 5 additions & 0 deletions sop-java-picocli/src/main/resources/msg_armor.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
#
# SPDX-License-Identifier: Apache-2.0
usage.header=Add ASCII Armor to standard input
label=Label to be used in the header and tail of the armoring
5 changes: 5 additions & 0 deletions sop-java-picocli/src/main/resources/msg_armor_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
#
# SPDX-License-Identifier: Apache-2.0
usage.header=Schütze Standard-Eingabe mit ASCII Armor
label=Label für Kopf- und Fußzeile der ASCII Armor
4 changes: 4 additions & 0 deletions sop-java-picocli/src/main/resources/msg_dearmor.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
#
# SPDX-License-Identifier: Apache-2.0
usage.header=Remove ASCII Armor from standard input
Loading

0 comments on commit 092a83a

Please sign in to comment.