fix option parsing
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user