implement optional variable argument/option ranges, refactor exception handling
adapt required/optional argument handling implement bounded/unbounded variable argument handling
This commit is contained in:
11
README.md
11
README.md
@@ -28,19 +28,20 @@ dependencies {
|
||||
## Usage
|
||||
|
||||
```kotlin
|
||||
fun main(args: Array<String>) = cli {
|
||||
fun main(args: Array<String>) = cli("application") {
|
||||
execute {
|
||||
// define execution of command (e.g., display help)
|
||||
println("Usage: application <command> [arguments] [options]")
|
||||
}
|
||||
|
||||
// declare command "greet"
|
||||
command("greet") {
|
||||
// declare arguments
|
||||
val speakersArg = Argument.string().variable().register()
|
||||
val speakersArg by Argument.string("speakers").variable(min = 1)
|
||||
|
||||
// declare options
|
||||
val greetingOpt = Option.string("greeting", "greet", "g").orElse("Hello").register()
|
||||
val nameOpt = Option.string("name", "n").orNull().register()
|
||||
val greetingOpt by Option.string("greeting", "greet", "g").orElse("Hello")
|
||||
val nameOpt by Option.string("name", "n").orNull()
|
||||
|
||||
execute {
|
||||
// retrieve the arguments and options
|
||||
@@ -55,7 +56,7 @@ fun main(args: Array<String>) = cli {
|
||||
}
|
||||
|
||||
// declare fallback command
|
||||
fallback { valueArg ->
|
||||
fallback("value") { valueArg ->
|
||||
execute {
|
||||
// retrieve the value used for the fallback command
|
||||
val value by valueArg
|
||||
|
||||
Reference in New Issue
Block a user