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

59 lines
1.4 KiB
Java
Raw Normal View History

2022-01-11 13:46:05 +01:00
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.cli.picocli.commands;
import picocli.CommandLine;
import sop.cli.picocli.Print;
import sop.cli.picocli.SopCLI;
2023-07-12 14:22:57 +02:00
import sop.exception.SOPGPException;
2022-01-11 13:46:05 +01:00
import sop.operation.Version;
@CommandLine.Command(name = "version", resourceBundle = "msg_version",
2023-07-12 14:22:57 +02:00
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
2022-05-29 21:17:03 +02:00
public class VersionCmd extends AbstractSopCmd {
2022-01-11 13:46:05 +01:00
@CommandLine.ArgGroup()
Exclusive exclusive;
static class Exclusive {
@CommandLine.Option(names = "--extended")
2022-01-11 13:46:05 +01:00
boolean extended;
@CommandLine.Option(names = "--backend")
2022-01-11 13:46:05 +01:00
boolean backend;
2023-04-14 14:41:37 +02:00
@CommandLine.Option(names = "--sop-spec")
boolean sopSpec;
2022-01-11 13:46:05 +01:00
}
@Override
public void run() {
2022-05-29 21:17:03 +02:00
Version version = throwIfUnsupportedSubcommand(
SopCLI.getSop().version(), "version");
2022-01-11 13:46:05 +01:00
if (exclusive == null) {
Print.outln(version.getName() + " " + version.getVersion());
return;
}
if (exclusive.extended) {
Print.outln(version.getExtendedVersion());
return;
}
if (exclusive.backend) {
Print.outln(version.getBackendVersion());
return;
}
2023-04-14 14:41:37 +02:00
if (exclusive.sopSpec) {
Print.outln(version.getSopSpecVersion());
return;
}
2022-01-11 13:46:05 +01:00
}
}