Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit 5dff687

Browse files
feat: print version name from properties file
1 parent 98c92b7 commit 5dff687

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

cli/src/main/kotlin/io/redgreen/cardbox/cli/CardboxCommand.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ package io.redgreen.cardbox.cli
33
import io.redgreen.cardbox.cli.commands.DiscoverCommand
44
import io.redgreen.cardbox.cli.commands.PackCommand
55
import picocli.CommandLine.Command
6-
7-
internal const val TOOL_VERSION = "0.1.0"
6+
import picocli.CommandLine.Option
87

98
@Command(
109
name = "cardbox",
11-
mixinStandardHelpOptions = true,
12-
subcommands = [DiscoverCommand::class, PackCommand::class],
13-
description = ["Create JARs from Android projects."],
10+
subcommands = [
11+
DiscoverCommand::class,
12+
PackCommand::class,
13+
],
14+
description = ["Create JARs from Android projects for jQAssistant."],
1415
commandListHeading = "%nCommands:%n%nAvailable commands are:%n",
15-
version = ["v$TOOL_VERSION"],
1616
)
17-
class CardboxCommand
17+
class CardboxCommand {
18+
@Option(
19+
names = ["--version", "-v"],
20+
description = ["prints version"],
21+
versionHelp = true,
22+
)
23+
var version: Boolean = false
24+
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
package io.redgreen.cardbox.cli
22

3+
import java.util.Properties
4+
import kotlin.system.exitProcess
35
import picocli.CommandLine
46

57
fun main(args: Array<String>) {
6-
CommandLine(CardboxCommand()).execute(*args)
8+
val commandLine = CommandLine(CardboxCommand())
9+
val exitCode = commandLine.execute(*args)
10+
11+
if (commandLine.isVersionHelpRequested) {
12+
printVersion()
13+
exitProcess(0)
14+
}
15+
16+
exitProcess(exitCode)
17+
}
18+
19+
fun printVersion() {
20+
val properties = CardboxCommand::class.java.classLoader
21+
.getResourceAsStream("version.properties").use { Properties().apply { load(it) } }
22+
println(properties["version"])
723
}

0 commit comments

Comments
 (0)