implement suggestions for unknown command/option

This commit is contained in:
2026-01-09 23:28:02 +01:00
parent ff87ae90f5
commit 562b9eb522
10 changed files with 97 additions and 15 deletions

View File

@@ -53,7 +53,7 @@ internal class ContextParser(
}
if (cmd == null) {
when {
command.arguments.isEmpty() -> return failure(path, UnknownCommand(current))
command.arguments.isEmpty() -> return failure(path, UnknownCommand(command, current))
else -> break
}
}
@@ -87,9 +87,9 @@ internal class ContextParser(
// argument
endOfOptions || dashes == 0 -> {
val argument = command.arguments.getOrNull(argumentIndex)
?: return failure(path, UnexpectedArgument())
?: return failure(path, UnexpectedArgument(current))
val value = when (val result = argument.parser.parse(trimmed)) {
val value = when (val result = argument.parser.parse(current)) {
is Parser.Result.Success<*> -> result.value
is Parser.Result.Failure<*> -> return failure(path, result.failure)
}
@@ -135,7 +135,7 @@ internal class ContextParser(
for (name in names) {
val option = command.options.firstOrNull { name in it.names }
?: return failure(path, UnknownOption(name))
?: return failure(path, UnknownOption(command, name))
val value = when {
text != null ->