improve command handling, change argument/option registration
This commit is contained in:
22
README.md
22
README.md
@@ -28,20 +28,20 @@ dependencies {
|
||||
## Usage
|
||||
|
||||
```kotlin
|
||||
fun main(args: Array<String>) = cli("application") {
|
||||
fun main(args: Array<String>) = command("application") {
|
||||
execute {
|
||||
// define execution of command (e.g., display help)
|
||||
help()
|
||||
}
|
||||
|
||||
// declare command "greet"
|
||||
command("greet") {
|
||||
// declare arguments
|
||||
val speakersArg by argument.string("speakers").variable(min = 1)
|
||||
// register command "greet"
|
||||
+command("greet") {
|
||||
// declare and register arguments
|
||||
val speakersArg = +argument.string("speakers").variable(min = 1)
|
||||
|
||||
// declare options
|
||||
val greetingOpt by option.string("greeting", "greet", "g").orElse("Hello")
|
||||
val nameOpt by option.string("name", "n").orNull()
|
||||
// declare and register options
|
||||
val greetingOpt = +option.string("greeting", "greet", "g").orElse("Hello")
|
||||
val nameOpt = +option.string("name", "n").orNull()
|
||||
|
||||
execute {
|
||||
// retrieve the arguments and options
|
||||
@@ -52,11 +52,11 @@ fun main(args: Array<String>) = cli("application") {
|
||||
println("${speakers.joinToString()}: $greeting ${name ?: "World"}!")
|
||||
}
|
||||
|
||||
// declare more commands...
|
||||
// register more commands...
|
||||
}
|
||||
|
||||
// declare fallback command
|
||||
fallback.string("value") { valueArg ->
|
||||
// register fallback command "value"
|
||||
+command.fallback.string("value") { valueArg ->
|
||||
execute {
|
||||
// retrieve the value used for the fallback command
|
||||
val value by valueArg
|
||||
|
||||
Reference in New Issue
Block a user