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:
2026-01-06 22:47:21 +01:00
parent 8e491751f5
commit 4e9b358ef8
49 changed files with 315 additions and 231 deletions

View File

@@ -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