Implement profiles

This commit is contained in:
Paul Schaub 2023-04-14 14:06:34 +02:00
parent b8544396f8
commit 5935d65c90
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
11 changed files with 75 additions and 43 deletions

View file

@ -31,7 +31,7 @@ public class GenerateKeyCmd extends AbstractSopCmd {
String withKeyPassword;
@CommandLine.Option(names = "--profile",
paramLabel = "PROFILE")
paramLabel = "PROFILE")
String profile = "default";
@Override
@ -47,7 +47,12 @@ public class GenerateKeyCmd extends AbstractSopCmd {
generateKey.noArmor();
}
generateKey.profile(profile);
try {
generateKey.profile(profile);
} catch (SOPGPException.UnsupportedProfile e) {
String errorMsg = getMsg("sop.error.usage.profile_not_supported", "generate-key", profile);
throw new SOPGPException.UnsupportedProfile(errorMsg, e);
}
if (withKeyPassword != null) {
try {

View file

@ -5,7 +5,9 @@
package sop.cli.picocli.commands;
import picocli.CommandLine;
import sop.Profile;
import sop.cli.picocli.SopCLI;
import sop.exception.SOPGPException;
import sop.operation.ListProfiles;
@CommandLine.Command(name = "list-profiles",
@ -13,7 +15,7 @@ import sop.operation.ListProfiles;
exitCodeOnInvalidInput = 37)
public class ListProfilesCmd extends AbstractSopCmd {
@CommandLine.Parameters(paramLabel = "COMMAND", arity="0..1", descriptionKey = "subcommand")
@CommandLine.Parameters(paramLabel = "COMMAND", arity="1", descriptionKey = "subcommand")
String subcommand;
@Override
@ -21,19 +23,15 @@ public class ListProfilesCmd extends AbstractSopCmd {
ListProfiles listProfiles = throwIfUnsupportedSubcommand(
SopCLI.getSop().listProfiles(), "list-profiles");
if (subcommand == null) {
for (String profile : listProfiles.global()) {
try {
for (Profile profile : listProfiles.subcommand(subcommand)) {
// CHECKSTYLE:OFF
System.out.println(profile);
// CHECKSTYLE:ON
}
return;
}
for (String profile : listProfiles.ofCommand(subcommand)) {
// CHECKSTYLE:OFF
System.out.println(profile);
// CHECKSTYLE:ON
} catch (SOPGPException.UnsupportedProfile e) {
String errorMsg = getMsg("sop.error.feature_support.subcommand_does_not_support_profiles", subcommand);
throw new SOPGPException.UnsupportedProfile(errorMsg, e);
}
}
}