All checks were successful
/ publish (push) Successful in 3m54s
Reviewed-on: Infendro/cli-kt#10
cli-kt
cli-kt is a Kotlin Multiplatform framework for implementing terminal applications.
Installation
Add the following to your build.gradle.kts.
repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")
}
dependencies {
implementation("com.infendro:cli:1.4.1")
}
Usage
fun main(args: Array<String>) = command("application", description = "example application") {
execute {
// define execution of command (e.g., display help)
help()
}
// register command "greet"
+command("greet", description = "greet someone") {
// declare and register arguments
val speakersArg = +argument.string("speakers", description = "the greeters").variable(min = 1)
// declare and register options
val greetingOpt = +option.string("greeting", "greet", "g", description = "the greeting").orElse("Hello")
val nameOpt = +option.string("name", "n", description = "the greetee").orNull()
execute {
// retrieve the arguments and options
val speakers by speakersArg
val greeting by greetingOpt
val name by nameOpt
println("${speakers.joinToString()}: $greeting ${name ?: "World"}!")
}
// register more commands...
}
// register fallback command "value"
+command.fallback.string("value", description = "execute an arbitrary command") { valueArg ->
execute {
// retrieve the value used for the fallback command
val value by valueArg
println("""command "$value" executed!""")
}
}
}.run(*args)
Description
Languages
Kotlin
100%