improve exceptions

This commit is contained in:
2026-01-08 19:42:48 +01:00
parent 6aa6c1b3c8
commit f33caa30c0
10 changed files with 21 additions and 15 deletions

View File

@@ -20,7 +20,7 @@ sealed class Command private constructor(
internal val renderer: HelpRenderer,
) {
init {
if (!name.matches(Regex.COMMAND)) throw InvalidCommand(name)
if (!name.matches(Regex.COMMAND)) throw InvalidCommandName(name)
}
fun run(args: Array<String>) {

View File

@@ -1,6 +1,6 @@
package com.infendro.cli.command.argument
import com.infendro.cli.error.build.InvalidArgument
import com.infendro.cli.error.build.InvalidArgumentName
import com.infendro.cli.error.build.InvalidRange
import com.infendro.cli.parser.Parser
import com.infendro.cli.util.Regex.ARGUMENT
@@ -13,7 +13,7 @@ sealed class Argument<T : Any>(
) {
init {
when {
!name.matches(ARGUMENT) -> throw InvalidArgument(name)
!name.matches(ARGUMENT) -> throw InvalidArgumentName(name)
min !in 0..count || max == 0 -> throw InvalidRange()
}
}

View File

@@ -1,6 +1,6 @@
package com.infendro.cli.command.option
import com.infendro.cli.error.build.InvalidOption
import com.infendro.cli.error.build.InvalidOptionName
import com.infendro.cli.error.build.InvalidRange
import com.infendro.cli.error.build.MissingOptionName
import com.infendro.cli.parser.Parser
@@ -35,7 +35,7 @@ sealed class Option<T : Any>(
init {
when {
names.isEmpty() -> throw MissingOptionName()
names.any { !it.matches(OPTION) } -> throw InvalidOption(name)
names.any { !it.matches(OPTION) } -> throw InvalidOptionName(name)
min !in 0..count || max == 0 -> throw InvalidRange()
}
}