improve exceptions
This commit is contained in:
@@ -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>) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
abstract class BuildException : Error()
|
||||
abstract class BuildException : Exception()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
import com.infendro.cli.command.argument.Argument
|
||||
|
||||
class DuplicateArgument(
|
||||
val name: String,
|
||||
val argument: Argument<*>,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
get() = """duplicate argument "$name""""
|
||||
get() = """duplicate argument "${argument.name}""""
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
import com.infendro.cli.command.Command
|
||||
|
||||
class DuplicateCommand(
|
||||
val command: String,
|
||||
val command: Command,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
get() = """duplicate command "$command""""
|
||||
get() = """duplicate command "${command.name}""""
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
import com.infendro.cli.command.option.Option
|
||||
|
||||
class DuplicateOption(
|
||||
val name: String,
|
||||
val option: Option<*>,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
get() = """duplicate option "$name""""
|
||||
get() = """duplicate option "${option.name}""""
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
class InvalidArgument(
|
||||
class InvalidArgumentName(
|
||||
val name: String,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
class InvalidCommand(
|
||||
class InvalidCommandName(
|
||||
val name: String,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.infendro.cli.error.build
|
||||
|
||||
class InvalidOption(
|
||||
class InvalidOptionName(
|
||||
val name: String,
|
||||
) : BuildException() {
|
||||
override val message: String
|
||||
Reference in New Issue
Block a user