Add usage and aliases to CommandDescriptor

This commit is contained in:
Him188 2020-05-14 08:25:53 +08:00
parent 4521cfbc9e
commit 33022deeae

View File

@ -13,13 +13,21 @@ class CommandDescriptor(
*/ */
val fullName: String, val fullName: String,
/** /**
* 指令参数解析器环境. * 用法说明
*/ */
val context: CommandParserContext, val usage: String,
/** /**
* 指令参数列表, 有顺序. * 指令参数列表, 有顺序.
*/ */
val params: List<CommandParam<*>>, val params: List<CommandParam<*>>,
/**
* 指令参数解析器环境.
*/
val context: CommandParserContext = CommandParserContext.Builtins,
/**
* 指令别名
*/
val aliases: Array<String> = arrayOf(),
/** /**
* 指令权限 * 指令权限
* *
@ -50,6 +58,12 @@ class CommandDescriptorBuilder(
@PublishedApi @PublishedApi
internal var params: MutableList<CommandParam<*>> = mutableListOf() internal var params: MutableList<CommandParam<*>> = mutableListOf()
@PublishedApi
internal var usage: String = "<no usage>"
@PublishedApi
internal var aliases: MutableList<String> = mutableListOf()
/** 增加指令参数解析器列表 */ /** 增加指令参数解析器列表 */
@JvmSynthetic @JvmSynthetic
inline fun context(block: CommandParserContextBuilder.() -> Unit) { inline fun context(block: CommandParserContextBuilder.() -> Unit) {
@ -73,6 +87,14 @@ class CommandDescriptorBuilder(
this.permission = AnonymousCommandPermission(block) this.permission = AnonymousCommandPermission(block)
} }
fun usage(message: String): CommandDescriptorBuilder = apply {
usage = message
}
fun alias(vararg name: String): CommandDescriptorBuilder = apply {
this.aliases.addAll(name)
}
fun param(vararg params: CommandParam<*>): CommandDescriptorBuilder = apply { fun param(vararg params: CommandParam<*>): CommandDescriptorBuilder = apply {
this.params.addAll(params) this.params.addAll(params)
} }
@ -120,7 +142,8 @@ class CommandDescriptorBuilder(
this.params.add(CommandParam(null, type.kotlin)) this.params.add(CommandParam(null, type.kotlin))
} }
fun build(): CommandDescriptor = CommandDescriptor(fullName, context, params, permission) fun build(): CommandDescriptor =
CommandDescriptor(fullName, context, params, usage, aliases.toTypedArray(), permission)
} }
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")