improve exceptions

This commit is contained in:
2026-01-07 22:00:32 +01:00
parent 921229aa5b
commit 2a9f086c9d
43 changed files with 137 additions and 92 deletions

View File

@@ -7,11 +7,9 @@ import com.infendro.cli.command.context.ContextParser
import com.infendro.cli.command.help.DefaultHelpRenderer
import com.infendro.cli.command.help.HelpRenderer
import com.infendro.cli.command.option.Option
import com.infendro.cli.exception.build.*
import com.infendro.cli.error.build.*
import com.infendro.cli.parser.*
import com.infendro.cli.util.Regex
import com.infendro.cli.util.Regex.ARGUMENT
import com.infendro.cli.util.Regex.OPTION
import kotlin.reflect.KProperty
sealed class Command private constructor(
@@ -205,15 +203,11 @@ sealed class Command private constructor(
argument.required && last.optional -> throw InvalidArgumentOrder()
}
}
if (!argument.name.matches(ARGUMENT)) throw InvalidArgument(argument.name)
}
private fun validateOption(option: Option<*>) {
for (name in option.names) {
when {
!name.matches(OPTION) -> throw InvalidOption(name)
options.any { name in it.names } -> throw DuplicateOption(name)
}
if (options.any { name in it.names }) throw DuplicateOption(name)
}
}
@@ -222,7 +216,7 @@ sealed class Command private constructor(
}
private fun validateRenderer() {
if (_renderer != null) throw Exception() //TODO
if (_renderer != null) throw DuplicateRenderer()
}
private fun validate() {