-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathSubCmdsViaMethods.kt
More file actions
42 lines (36 loc) · 1.76 KB
/
Copy pathSubCmdsViaMethods.kt
File metadata and controls
42 lines (36 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package picocli.examples.kotlin
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.HelpCommand
import java.util.Locale
import kotlin.system.exitProcess
@Command(name = "ISOCodeResolve", mixinStandardHelpOptions = true, version = ["1.0"], subcommands = [ HelpCommand::class ],
description = ["Resolve ISO country codes (ISO-3166-1) or language codes (ISO 639-1 or -2)"])
class SubCmdsViaMethods : Runnable {
@CommandLine.Spec
val spec: CommandLine.Model.CommandSpec? = null
@Command(description = ["Resolve ISO country code (ISO-3166-1, Alpha-2 code)"])
fun country( @CommandLine.Parameters( arity = "1..*n", paramLabel = "<country code>",
description = ["country code(s) to be resolved"] ) vararg countryCodes : String)
{
for (code in countryCodes) {
println("${code.uppercase()}: " + Locale("", code).displayCountry)
}
}
@Command(description = ["Resolve ISO language code (ISO 639-1 or -2, two/three letters)"])
fun language( @CommandLine.Parameters( arity = "1..*n", paramLabel = "<language code>",
description = ["language code(s) to be resolved"] ) vararg languageCodes : String)
{
for (code in languageCodes) {
println("${code.uppercase()}: " + Locale(code).displayLanguage)
}
}
override fun run() = throw CommandLine.ParameterException(spec?.commandLine(), "Specify a subcommand")
companion object {
@JvmStatic fun main(args: Array<String>) {
CommandLine(SubCmdsViaMethods()).execute(*args)
}
}
}
// NOTE: below is an alternative to defining a @JvmStatic main function in a companion object:
// fun main(args: Array<String>) : Unit = exitProcess(CommandLine(SubCmdsViaMethods()).execute(*args))