mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-22 12:57:57 +01:00
Kotlin conversion: VersionCmd
This commit is contained in:
parent
a8829350a8
commit
1de179c015
2 changed files with 51 additions and 58 deletions
|
@ -1,58 +0,0 @@
|
|||
// 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.exception.SOPGPException;
|
||||
import sop.operation.Version;
|
||||
|
||||
@CommandLine.Command(name = "version", resourceBundle = "msg_version",
|
||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||
public class VersionCmd extends AbstractSopCmd {
|
||||
|
||||
@CommandLine.ArgGroup()
|
||||
Exclusive exclusive;
|
||||
|
||||
static class Exclusive {
|
||||
@CommandLine.Option(names = "--extended")
|
||||
boolean extended;
|
||||
|
||||
@CommandLine.Option(names = "--backend")
|
||||
boolean backend;
|
||||
|
||||
@CommandLine.Option(names = "--sop-spec")
|
||||
boolean sopSpec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
if (exclusive.sopSpec) {
|
||||
Print.outln(version.getSopSpecVersion());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.cli.picocli.commands
|
||||
|
||||
import picocli.CommandLine.ArgGroup
|
||||
import picocli.CommandLine.Command
|
||||
import picocli.CommandLine.Option
|
||||
import sop.cli.picocli.SopCLI
|
||||
import sop.exception.SOPGPException
|
||||
|
||||
@Command(
|
||||
name = "version",
|
||||
resourceBundle = "msg_version",
|
||||
exitCodeOnInvalidInput = SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||
class VersionCmd : AbstractSopCmd() {
|
||||
|
||||
@ArgGroup var exclusive: Exclusive? = null
|
||||
|
||||
class Exclusive {
|
||||
@Option(names = ["--extended"]) var extended: Boolean = false
|
||||
@Option(names = ["--backend"]) var backend: Boolean = false
|
||||
@Option(names = ["--sop-spec"]) var sopSpec: Boolean = false
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
val version = throwIfUnsupportedSubcommand(SopCLI.getSop().version(), "version")
|
||||
|
||||
if (exclusive == null) {
|
||||
// No option provided
|
||||
println("${version.getName()} ${version.getVersion()}")
|
||||
return
|
||||
}
|
||||
|
||||
if (exclusive!!.extended) {
|
||||
println(version.getExtendedVersion())
|
||||
return
|
||||
}
|
||||
|
||||
if (exclusive!!.backend) {
|
||||
println(version.getBackendVersion())
|
||||
return
|
||||
}
|
||||
|
||||
if (exclusive!!.sopSpec) {
|
||||
println(version.getSopSpecVersion())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue