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

@@ -31,7 +31,7 @@ class Context internal constructor(
operator fun Command.Key.getValue(thisRef: Any?, property: KProperty<*>): String = commands[index].name
private val <T : Any> Argument<T>.index: Int
get() = command.arguments.indexOf(this)
get() = command.arguments.takeWhile { it != this }.sumOf { it.count }
@Suppress("UNCHECKED_CAST")
private val <T : Any> Argument<T>.value: T?
@@ -39,7 +39,7 @@ class Context internal constructor(
@Suppress("UNCHECKED_CAST")
private val <T : Any> Argument.Variable<T>.values: List<T>
get() = arguments.drop(index).map { it.value as T }
get() = arguments.drop(index).take(count).map { it.value as T }
operator fun <T : Any> Argument.Required<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value!!
operator fun <T : Any> Argument.OrElse<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value ?: other