mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-06-25 21:14:53 +02:00
Since picocli 4.7.0, subcommands inherit resources from their parent commands, so we can store shared stuff like error msgs etc. in the parent (sop) resources file. This enables us to rename the parent command downstream (e.g. in pgpainless-cli). Only the help command breaks when renaming the parent command. TODO: Fix
52 lines
1.3 KiB
Java
52 lines
1.3 KiB
Java
// 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;
|
|
import sop.operation.Version;
|
|
|
|
@CommandLine.Command(name = "version", resourceBundle = "version",
|
|
exitCodeOnInvalidInput = 37)
|
|
public class VersionCmd extends AbstractSopCmd {
|
|
|
|
@CommandLine.ArgGroup()
|
|
Exclusive exclusive;
|
|
|
|
static class Exclusive {
|
|
@CommandLine.Option(names = "--extended",
|
|
descriptionKey = "usage.option.extended")
|
|
boolean extended;
|
|
|
|
@CommandLine.Option(names = "--backend",
|
|
descriptionKey = "usage.option.backend")
|
|
boolean backend;
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public void run() {
|
|
Version version = throwIfUnsupportedSubcommand(
|
|
SopCLI.getSop().version(), "version");
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|