mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-15 13:19:45 +02:00
Wip: Refactor command implementation and enable i18n for CLI
This commit is contained in:
parent
a7f02d58cc
commit
4934e472e2
34 changed files with 980 additions and 782 deletions
|
@ -4,33 +4,31 @@
|
|||
|
||||
package sop.cli.picocli.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import sop.Ready;
|
||||
import sop.cli.picocli.FileUtil;
|
||||
import sop.cli.picocli.Print;
|
||||
import sop.cli.picocli.SopCLI;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.operation.GenerateKey;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandLine.Command(name = "generate-key",
|
||||
description = "Generate a secret key",
|
||||
resourceBundle = "sop",
|
||||
exitCodeOnInvalidInput = 37)
|
||||
public class GenerateKeyCmd extends AbstractSopCmd {
|
||||
|
||||
@CommandLine.Option(names = "--no-armor",
|
||||
description = "ASCII armor the output",
|
||||
descriptionKey = "sop.generate-key.usage.option.armor",
|
||||
negatable = true)
|
||||
boolean armor = true;
|
||||
|
||||
@CommandLine.Parameters(description = "User-ID, eg. \"Alice <alice@example.com>\"")
|
||||
@CommandLine.Parameters(descriptionKey = "sop.generate-key.usage.option.user_id")
|
||||
List<String> userId = new ArrayList<>();
|
||||
|
||||
@CommandLine.Option(names = "--with-key-password",
|
||||
description = "Indirect file type pointing to file containing password to protect the key",
|
||||
descriptionKey = "sop.generate-key.usage.option.with_key_password",
|
||||
paramLabel = "PASSWORD")
|
||||
String withKeyPassword;
|
||||
|
||||
|
@ -49,10 +47,11 @@ public class GenerateKeyCmd extends AbstractSopCmd {
|
|||
|
||||
if (withKeyPassword != null) {
|
||||
try {
|
||||
String password = FileUtil.stringFromInputStream(FileUtil.getFileInputStream(withKeyPassword));
|
||||
String password = stringFromInputStream(getInput(withKeyPassword));
|
||||
generateKey.withKeyPassword(password);
|
||||
} catch (SOPGPException.UnsupportedOption e) {
|
||||
throw new SOPGPException.UnsupportedOption("Option '--with-key-password' is not supported.");
|
||||
String errorMsg = getMsg("sop.error.feature_support.option_not_supported", "--with-key-password");
|
||||
throw new SOPGPException.UnsupportedOption(errorMsg, e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -61,18 +60,8 @@ public class GenerateKeyCmd extends AbstractSopCmd {
|
|||
try {
|
||||
Ready ready = generateKey.generate();
|
||||
ready.writeTo(System.out);
|
||||
} catch (SOPGPException.MissingArg missingArg) {
|
||||
Print.errln("Missing argument.");
|
||||
Print.trace(missingArg);
|
||||
System.exit(missingArg.getExitCode());
|
||||
} catch (SOPGPException.UnsupportedAsymmetricAlgo unsupportedAsymmetricAlgo) {
|
||||
Print.errln("Unsupported asymmetric algorithm.");
|
||||
Print.trace(unsupportedAsymmetricAlgo);
|
||||
System.exit(unsupportedAsymmetricAlgo.getExitCode());
|
||||
} catch (IOException e) {
|
||||
Print.errln("IO Error.");
|
||||
Print.trace(e);
|
||||
System.exit(1);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue