Add list-profiles command

This commit is contained in:
Paul Schaub 2023-04-11 15:06:37 +02:00
parent 17b305924c
commit 83a003e80f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
14 changed files with 216 additions and 0 deletions

View file

@ -30,6 +30,10 @@ public class GenerateKeyCmd extends AbstractSopCmd {
paramLabel = "PASSWORD")
String withKeyPassword;
@CommandLine.Option(names = "--profile",
paramLabel = "PROFILE")
String profile = "default";
@Override
public void run() {
GenerateKey generateKey = throwIfUnsupportedSubcommand(
@ -43,6 +47,8 @@ public class GenerateKeyCmd extends AbstractSopCmd {
generateKey.noArmor();
}
generateKey.profile(profile);
if (withKeyPassword != null) {
try {
String password = stringFromInputStream(getInput(withKeyPassword));

View file

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.cli.picocli.commands;
import picocli.CommandLine;
import sop.cli.picocli.SopCLI;
import sop.operation.ListProfiles;
@CommandLine.Command(name = "list-profiles",
resourceBundle = "msg_list-profiles",
exitCodeOnInvalidInput = 37)
public class ListProfilesCmd extends AbstractSopCmd {
@CommandLine.Parameters(paramLabel = "COMMAND", arity="0..1", descriptionKey = "subcommand")
String subcommand;
@Override
public void run() {
ListProfiles listProfiles = throwIfUnsupportedSubcommand(
SopCLI.getSop().listProfiles(), "list-profiles");
if (subcommand == null) {
for (String profile : listProfiles.global()) {
// CHECKSTYLE:OFF
System.out.println(profile);
// CHECKSTYLE:ON
}
return;
}
for (String profile : listProfiles.ofCommand(subcommand)) {
// CHECKSTYLE:OFF
System.out.println(profile);
// CHECKSTYLE:ON
}
}
}