fix option parsing

This commit is contained in:
2026-01-08 22:21:41 +01:00
parent fa5fa89bec
commit 47834c91d8

View File

@@ -31,7 +31,7 @@ internal class ContextParser(
private val current: String private val current: String
get() = args[index] get() = args[index]
private val next: String? private val next: String?
get() = args.getOrNull(index) get() = args.getOrNull(index + 1)
private fun hasNext() = index < args.size private fun hasNext() = index < args.size
private fun consume() { private fun consume() {
@@ -121,7 +121,7 @@ internal class ContextParser(
else -> { else -> {
if (next?.startsWith('-') == false) { if (next?.startsWith('-') == false) {
consume() consume()
trimmed to next trimmed to current
} else { } else {
trimmed to null trimmed to null
} }
@@ -139,7 +139,7 @@ internal class ContextParser(
val value = when { val value = when {
text != null -> text != null ->
when (val result = option.parser.parse(current)) { when (val result = option.parser.parse(text)) {
is Parser.Result.Success<*> -> result.value is Parser.Result.Success<*> -> result.value
is Parser.Result.Failure<*> -> return failure(path, result.failure) is Parser.Result.Failure<*> -> return failure(path, result.failure)
} }