Archived
0

Tweaks and fixes

This commit is contained in:
Dico Karssiens
2018-07-29 01:03:31 +01:00
parent 547ffcb0ba
commit d425a1e977
19 changed files with 504 additions and 203 deletions

View File

@@ -1,9 +1,13 @@
package io.dico.parcels2.command
import io.dico.dicore.command.CommandBuilder
import io.dico.dicore.command.ICommandAddress
import io.dico.dicore.command.ICommandDispatcher
import io.dico.dicore.command.predef.PredefinedCommand
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
import io.dico.parcels2.ParcelsPlugin
import io.dico.parcels2.logger
import java.util.*
@Suppress("UsePropertyAccessSyntax")
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
@@ -18,7 +22,7 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
.registerCommands(CommandsAddedStatus(plugin))
.group("option")
.apply { CommandsParcelOptions.setGroupDescription(this) }
//.apply { CommandsParcelOptions.setGroupDescription(this) }
.registerCommands(CommandsParcelOptions(plugin))
.parent()
@@ -29,15 +33,34 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
.putDebugCommands(plugin)
.parent()
.generateHelpAndSyntaxCommands()
.getDispatcher()
//@formatter:on
}
private fun CommandBuilder.putDebugCommands(plugin: ParcelsPlugin): CommandBuilder {
if (!logger.isDebugEnabled) return this
//if (!logger.isDebugEnabled) return this
//@formatter:off
return group("debug", "d")
.registerCommands(CommandsDebug(plugin))
.parent()
//@formatter:on
}
private fun CommandBuilder.generateHelpAndSyntaxCommands(): CommandBuilder {
generateCommands(dispatcher as ICommandAddress, "help", "syntax")
return this
}
private fun generateCommands(address: ICommandAddress, vararg names: String) {
val addresses: Queue<ICommandAddress> = LinkedList()
addresses.offer(address)
while (addresses.isNotEmpty()) {
val cur = addresses.poll()
addresses.addAll(cur.children.values.distinct())
if (cur.hasCommand()) {
ReflectiveRegistration.generateCommands(cur, names)
}
}
}