improve argument creation, improve fallback command
This commit is contained in:
@@ -35,16 +35,26 @@ class Command private constructor(
|
||||
private val key: Key
|
||||
get() = Key(level)
|
||||
|
||||
fun command(name: String? = null, block: Builder.(Key) -> Unit) {
|
||||
fun command(name: String, block: Builder.() -> Unit) {
|
||||
// validate
|
||||
val last = commands.lastOrNull()
|
||||
when {
|
||||
last != null && last.fallback -> throw CommandOrderException()
|
||||
name != null && !name.matches(COMMAND) -> throw IllegalCommandNameException(name)
|
||||
!name.matches(COMMAND) -> throw IllegalCommandNameException(name)
|
||||
commands.any { it.name == name } -> throw DuplicateCommandException(name)
|
||||
}
|
||||
|
||||
commands += Builder(level + 1, name).also { it.block(it.key) }.build()
|
||||
commands += Builder(level + 1, name).also(block).build()
|
||||
}
|
||||
|
||||
fun fallback(block: Builder.(Key) -> Unit) {
|
||||
// validate
|
||||
val last = commands.lastOrNull()
|
||||
when {
|
||||
last != null && last.fallback -> throw CommandOrderException()
|
||||
}
|
||||
|
||||
commands += Builder(level + 1, null).also { it.block(it.key) }.build()
|
||||
}
|
||||
|
||||
fun argument(argument: Argument<*>) {
|
||||
|
||||
Reference in New Issue
Block a user