sop-java/sop-java-picocli/src/main/java/sop/cli/picocli/commands/ListProfilesCmd.java

37 lines
1.2 KiB
Java
Raw Normal View History

2023-04-11 15:06:37 +02:00
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.cli.picocli.commands;
import picocli.CommandLine;
2023-04-14 14:06:34 +02:00
import sop.Profile;
import sop.cli.picocli.Print;
2023-04-11 15:06:37 +02:00
import sop.cli.picocli.SopCLI;
2023-04-14 14:06:34 +02:00
import sop.exception.SOPGPException;
2023-04-11 15:06:37 +02:00
import sop.operation.ListProfiles;
@CommandLine.Command(name = "list-profiles",
resourceBundle = "msg_list-profiles",
2023-07-12 14:22:57 +02:00
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
2023-04-11 15:06:37 +02:00
public class ListProfilesCmd extends AbstractSopCmd {
2023-04-17 14:12:01 +02:00
@CommandLine.Parameters(paramLabel = "COMMAND", arity = "1", descriptionKey = "subcommand")
2023-04-11 15:06:37 +02:00
String subcommand;
@Override
public void run() {
ListProfiles listProfiles = throwIfUnsupportedSubcommand(
SopCLI.getSop().listProfiles(), "list-profiles");
2023-04-14 14:06:34 +02:00
try {
for (Profile profile : listProfiles.subcommand(subcommand)) {
Print.outln(profile.toString());
2023-04-11 15:06:37 +02:00
}
2023-04-14 14:06:34 +02:00
} catch (SOPGPException.UnsupportedProfile e) {
String errorMsg = getMsg("sop.error.feature_support.subcommand_does_not_support_profiles", subcommand);
throw new SOPGPException.UnsupportedProfile(errorMsg, e);
2023-04-11 15:06:37 +02:00
}
}
}