diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 19de48d..d95cae4 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -414,7 +414,7 @@ performance: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.Test.kt', '**/*.Spec.kt', '**/*.Spek.kt'] SpreadOperator: - active: true + active: false excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.Test.kt', '**/*.Spec.kt', '**/*.Spek.kt'] UnnecessaryTemporaryInstantiation: active: true diff --git a/kordx-commands-runtime-kord/src/main/kotlin/com/gitlab/kordlib/kordx/commands/kord/module/Commands.kt b/kordx-commands-runtime-kord/src/main/kotlin/com/gitlab/kordlib/kordx/commands/kord/module/Commands.kt index 22c8825..9aa0f3e 100644 --- a/kordx-commands-runtime-kord/src/main/kotlin/com/gitlab/kordlib/kordx/commands/kord/module/Commands.kt +++ b/kordx-commands-runtime-kord/src/main/kotlin/com/gitlab/kordlib/kordx/commands/kord/module/Commands.kt @@ -9,12 +9,13 @@ import com.gitlab.kordlib.kordx.commands.model.module.CommandSet */ fun commands( builder: KordModuleBuilder.() -> Unit -) = com.gitlab.kordlib.kordx.commands.model.module.commands(KordContext, builder) +): CommandSet = com.gitlab.kordlib.kordx.commands.model.module.commands(KordContext, builder) /** - * Defines a [CommandSet] with a single command with the given [name] and configured by the [builder]. + * Defines a [CommandSet] with a single command with the given [name], [aliases] and configured by the [builder]. */ fun command( name: String, + vararg aliases: String, builder: KordCommandBuilder.() -> Unit -): CommandSet = com.gitlab.kordlib.kordx.commands.model.module.command(KordContext, name, builder) +): CommandSet = com.gitlab.kordlib.kordx.commands.model.module.command(KordContext, name, *aliases, builder = builder) diff --git a/kordx-commands-runtime-kord/src/test/kotlin/commands/example/MathCommands.kt b/kordx-commands-runtime-kord/src/test/kotlin/commands/example/MathCommands.kt index 356aed6..524aa4e 100644 --- a/kordx-commands-runtime-kord/src/test/kotlin/commands/example/MathCommands.kt +++ b/kordx-commands-runtime-kord/src/test/kotlin/commands/example/MathCommands.kt @@ -14,9 +14,9 @@ import com.gitlab.kordlib.kordx.commands.model.command.invoke @ModuleName("math") fun simpleMath() = commands { - command("add") { + command("add", "+") { - alias("+", "combine") + alias("combine") invoke(DoubleArgument, DoubleArgument) { a, b -> respond("${a + b}") diff --git a/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/CommandSet.kt b/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/CommandSet.kt index 7d69249..bebe802 100644 --- a/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/CommandSet.kt +++ b/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/CommandSet.kt @@ -41,7 +41,7 @@ interface CommandSet { /** * Defines a [CommandSet] configured by the [builder]. */ -fun commands( +fun commands( context: ProcessorContext, builder: ModuleBuilder.() -> Unit ): CommandSet = object : CommandSet { @@ -51,11 +51,12 @@ fun commands( } /** -* Defines a [CommandSet] with a single command with the given [name] and configured by the [builder]. -*/ -fun command( + * Defines a [CommandSet] with a single command with the given [name], [aliases] and configured by the [builder]. + */ +fun command( context: ProcessorContext, name: String, + vararg aliases: String, builder: CommandBuilder.() -> Unit -): CommandSet = commands(context) { command(name, builder) } +): CommandSet = commands(context) { command(name, *aliases, builder = builder) } diff --git a/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/ModuleBuilder.kt b/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/ModuleBuilder.kt index 673aaec..01bb1c5 100644 --- a/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/ModuleBuilder.kt +++ b/kordx-commands-runtime/src/main/kotlin/com/gitlab/kordlib/kordx/commands/model/module/ModuleBuilder.kt @@ -62,25 +62,27 @@ data class ModuleBuilder( } /** - * Adds a new command under the given [name] configured by the [builder] under the default [context]. + * Adds a new command under the given [name], [aliases] configured by the [builder] under the default [context]. */ inline fun command( name: String, + vararg aliases: String, builder: CommandBuilder.() -> Unit - ) { - val command = CommandBuilder(name, this.name, context).apply(builder) - add(command) - } + ): Unit = command(name, context, *aliases, builder = builder) /** - * Adds a new command under the given [name] configured by the [builder] under a new [context]. + * Adds a new command under the given [name], [aliases] configured by the [builder] under a new [context]. */ inline fun command( name: String, context: ProcessorContext, + vararg aliases: String, builder: CommandBuilder.() -> Unit ) { val command = CommandBuilder(name, this.name, context).apply(builder) + .apply { + alias(*aliases) + } add(command) }