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

@ -16,6 +16,7 @@ import sop.cli.picocli.commands.ExtractCertCmd;
import sop.cli.picocli.commands.GenerateKeyCmd;
import sop.cli.picocli.commands.InlineSignCmd;
import sop.cli.picocli.commands.InlineVerifyCmd;
import sop.cli.picocli.commands.ListProfilesCmd;
import sop.cli.picocli.commands.SignCmd;
import sop.cli.picocli.commands.VerifyCmd;
import sop.cli.picocli.commands.VersionCmd;
@ -41,6 +42,7 @@ import java.util.ResourceBundle;
VerifyCmd.class,
InlineSignCmd.class,
InlineVerifyCmd.class,
ListProfilesCmd.class,
VersionCmd.class,
AutoComplete.GenerateCompletion.class
}

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
}
}
}

View file

@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
#
# SPDX-License-Identifier: Apache-2.0
usage.header=Emit a list of profiles supported by the identified subcommand
subcommand=Subcommand for which to list profiles
# Generic TODO: Remove when bumping picocli to 4.7.0
usage.synopsisHeading=Usage:\u0020
usage.commandListHeading = %nCommands:%n
usage.optionListHeading = %nOptions:%n
usage.footerHeading=Powered by picocli%n

View file

@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
#
# SPDX-License-Identifier: Apache-2.0
usage.header=Gebe eine Liste von Profilen aus, welche vom angegebenen Unterbefehl unterstützt werden
subcommand=Unterbefehl für welchen Profile gelistet werden sollen
# Generic TODO: Remove when bumping picocli to 4.7.0
usage.synopsisHeading=Aufruf:\u0020
usage.commandListHeading=%nBefehle:%n
usage.optionListHeading = %nOptionen:%n
usage.footerHeading=Powered by Picocli%n

View file

@ -26,6 +26,7 @@ import sop.operation.InlineSign;
import sop.operation.InlineVerify;
import sop.operation.DetachedSign;
import sop.operation.DetachedVerify;
import sop.operation.ListProfiles;
import sop.operation.Version;
public class SOPTest {
@ -95,6 +96,11 @@ public class SOPTest {
return null;
}
@Override
public ListProfiles listProfiles() {
return null;
}
@Override
public InlineDetach inlineDetach() {
return null;