diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt index dbbdc374..735eef50 100644 --- a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt +++ b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt @@ -53,10 +53,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public constructor( - name: String, - description: Description = Description.empty(), - aliases: Array = emptyArray(), - commandManager: CommandManager + name: String, + description: Description = Description.empty(), + aliases: Array = emptyArray(), + commandManager: CommandManager ) { this.commandManager = commandManager this.commandBuilder = commandManager.commandBuilder(name, description, *aliases) @@ -73,18 +73,18 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public constructor( - name: String, - description: Description = Description.empty(), - aliases: Array = emptyArray(), - commandManager: CommandManager, - lambda: MutableCommandBuilder.() -> Unit + name: String, + description: Description = Description.empty(), + aliases: Array = emptyArray(), + commandManager: CommandManager, + lambda: MutableCommandBuilder.() -> Unit ) : this(name, description, aliases, commandManager) { lambda(this) } private constructor( - commandManager: CommandManager, - commandBuilder: Command.Builder + commandManager: CommandManager, + commandBuilder: Command.Builder ) { this.commandManager = commandManager this.commandBuilder = commandBuilder @@ -97,7 +97,7 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun build(): Command = - this.commandBuilder.build() + this.commandBuilder.build() /** * Invoke the provided receiver lambda on this builder, then build a [Command] from the resulting state @@ -107,7 +107,7 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun build( - lambda: MutableCommandBuilder.() -> Unit + lambda: MutableCommandBuilder.() -> Unit ): Command { lambda(this) return this.commandBuilder.build() @@ -121,14 +121,14 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun mutate( - mutator: (Command.Builder) -> Command.Builder + mutator: (Command.Builder) -> Command.Builder ): MutableCommandBuilder { this.commandBuilder = mutator(this.commandBuilder) return this } private fun onlyMutate( - mutator: (Command.Builder) -> Command.Builder + mutator: (Command.Builder) -> Command.Builder ): Unit { mutate(mutator) } @@ -140,7 +140,7 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun copy(): MutableCommandBuilder = - MutableCommandBuilder(this.commandManager, this.commandBuilder) + MutableCommandBuilder(this.commandManager, this.commandBuilder) /** * Make a new copy of this [MutableCommandBuilder] and invoke the provided receiver lambda on it @@ -150,11 +150,11 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun copy( - lambda: MutableCommandBuilder.() -> Unit + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy().apply { - lambda(this) - } + copy().apply { + lambda(this) + } /** * Make a new copy of this [MutableCommandBuilder], append a literal, and invoke the provided receiver lambda on it @@ -166,14 +166,14 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun copy( - literal: String, - description: Description, - lambda: MutableCommandBuilder.() -> Unit + literal: String, + description: Description, + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy().apply { - literal(literal, description) - lambda(this) - } + copy().apply { + literal(literal, description) + lambda(this) + } /** * Make a new copy of this [MutableCommandBuilder], append a literal, and invoke the provided receiver lambda on it @@ -184,13 +184,13 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun copy( - literal: String, - lambda: MutableCommandBuilder.() -> Unit + literal: String, + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy().apply { - literal(literal) - lambda(this) - } + copy().apply { + literal(literal) + lambda(this) + } /** * Build and register this command with the owning command manager @@ -200,9 +200,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun register(): MutableCommandBuilder = - apply { - this.commandManager.command(this) - } + apply { + this.commandManager.command(this) + } /** * Create a new copy of this mutable builder, act on it with a receiver lambda, and then register it with the owning @@ -214,9 +214,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun registerCopy( - lambda: MutableCommandBuilder.() -> Unit + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy(lambda).register() + copy(lambda).register() /** * Create a new copy of this mutable builder, append a literal, act on it with a receiver lambda, and then register it with @@ -230,10 +230,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun registerCopy( - literal: String, - lambda: MutableCommandBuilder.() -> Unit + literal: String, + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy(literal, lambda).register() + copy(literal, lambda).register() /** * Create a new copy of this mutable builder, append a literal, act on it with a receiver lambda, and then register it with @@ -248,11 +248,11 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun registerCopy( - literal: String, - description: Description, - lambda: MutableCommandBuilder.() -> Unit + literal: String, + description: Description, + lambda: MutableCommandBuilder.() -> Unit ): MutableCommandBuilder = - copy(literal, description, lambda).register() + copy(literal, description, lambda).register() /** * Set the value for a certain [CommandMeta.Key] in the command meta storage for this builder @@ -264,10 +264,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun meta( - key: CommandMeta.Key, - value: T + key: CommandMeta.Key, + value: T ): MutableCommandBuilder = - mutate { it.meta(key, value) } + mutate { it.meta(key, value) } /** * Set the value for a certain [CommandMeta.Key] in the command meta storage for this builder @@ -278,9 +278,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public infix fun CommandMeta.Key.to( - value: T + value: T ): MutableCommandBuilder = - meta(this, value) + meta(this, value) /** * Set the [CommandMeta.DESCRIPTION] meta for this command @@ -290,9 +290,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun commandDescription( - description: String + description: String ): MutableCommandBuilder = - meta(CommandMeta.DESCRIPTION, description) + meta(CommandMeta.DESCRIPTION, description) /** * Set the [CommandMeta.LONG_DESCRIPTION] meta for this command @@ -302,9 +302,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun longCommandDescription( - description: String + description: String ): MutableCommandBuilder = - meta(CommandMeta.LONG_DESCRIPTION, description) + meta(CommandMeta.LONG_DESCRIPTION, description) /** * Set the [CommandMeta.HIDDEN] meta for this command @@ -314,9 +314,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun hidden( - hidden: Boolean = true + hidden: Boolean = true ): MutableCommandBuilder = - meta(CommandMeta.HIDDEN, hidden) + meta(CommandMeta.HIDDEN, hidden) /** * Specify a required sender type @@ -326,7 +326,7 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public inline fun senderType(): MutableCommandBuilder = - mutate { it.senderType(T::class) } + mutate { it.senderType(T::class) } /** * Specify a required sender type @@ -336,9 +336,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun senderType( - type: KClass + type: KClass ): MutableCommandBuilder = - mutate { it.senderType(type) } + mutate { it.senderType(type) } /** * Field to get and set the required sender type for this command builder @@ -360,9 +360,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun senderType( - type: Class + type: Class ): MutableCommandBuilder = - mutate { it.senderType(type) } + mutate { it.senderType(type) } /** * Specify a permission required to execute this command @@ -372,9 +372,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun permission( - permission: String + permission: String ): MutableCommandBuilder = - mutate { it.permission(permission) } + mutate { it.permission(permission) } /** * Specify a permission required to execute this command @@ -384,9 +384,9 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun permission( - permission: CommandPermission + permission: CommandPermission ): MutableCommandBuilder = - mutate { it.permission(permission) } + mutate { it.permission(permission) } /** * Field to get and set the required permission for this command builder @@ -415,10 +415,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun argument( - argument: CommandArgument, - description: Description = Description.empty() + argument: CommandArgument, + description: Description = Description.empty() ): MutableCommandBuilder = - mutate { it.argument(argument, description) } + mutate { it.argument(argument, description) } /** * Add a new argument to this command @@ -429,10 +429,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun argument( - argument: CommandArgument.Builder, - description: Description = Description.empty() + argument: CommandArgument.Builder, + description: Description = Description.empty() ): MutableCommandBuilder = - mutate { it.argument(argument, description) } + mutate { it.argument(argument, description) } /** * Add a new argument to this command @@ -443,10 +443,10 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun argument( - description: Description = Description.empty(), - argumentSupplier: () -> CommandArgument + description: Description = Description.empty(), + argumentSupplier: () -> CommandArgument ): MutableCommandBuilder = - mutate { it.argument(argumentSupplier(), description) } + mutate { it.argument(argumentSupplier(), description) } /** * Add a new literal argument to this command @@ -458,11 +458,11 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun literal( - name: String, - description: Description = Description.empty(), - vararg aliases: String + name: String, + description: Description = Description.empty(), + vararg aliases: String ): MutableCommandBuilder = - mutate { it.literal(name, description, *aliases) } + mutate { it.literal(name, description, *aliases) } /** * Set the [CommandExecutionHandler] for this builder @@ -472,7 +472,104 @@ public class MutableCommandBuilder { * @since 1.3.0 */ public fun handler( - handler: CommandExecutionHandler + handler: CommandExecutionHandler ): MutableCommandBuilder = - mutate { it.handler(handler) } + mutate { it.handler(handler) } + + /** + * Add a new flag argument to this command + * + * @param name name of the flag + * @param aliases flag aliases + * @param description description of the flag + * @param argumentSupplier argument supplier for the flag + * @return this mutable builder + * @since 1.4.0 + */ + public fun flag( + name: String, + aliases: Array = emptyArray(), + description: Description = Description.empty(), + argumentSupplier: () -> CommandArgument + ): MutableCommandBuilder = mutate { + it.flag( + this.commandManager.flagBuilder(name) + .withAliases(*aliases) + .withDescription(description) + .withArgument(argumentSupplier()) + .build() + ) + } + + /** + * Add a new flag argument to this command + * + * @param name name of the flag + * @param aliases flag aliases + * @param description description of the flag + * @param argument argument for the flag + * @return this mutable builder + * @since 1.4.0 + */ + public fun flag( + name: String, + aliases: Array = emptyArray(), + description: Description = Description.empty(), + argument: CommandArgument + ): MutableCommandBuilder = mutate { + it.flag( + this.commandManager.flagBuilder(name) + .withAliases(*aliases) + .withDescription(description) + .withArgument(argument) + .build() + ) + } + + /** + * Add a new flag argument to this command + * + * @param name name of the flag + * @param aliases flag aliases + * @param description description of the flag + * @param argumentBuilder command argument builder for the flag + * @return this mutable builder + * @since 1.4.0 + */ + public fun flag( + name: String, + aliases: Array = emptyArray(), + description: Description = Description.empty(), + argumentBuilder: CommandArgument.Builder + ): MutableCommandBuilder = mutate { + it.flag( + this.commandManager.flagBuilder(name) + .withAliases(*aliases) + .withDescription(description) + .withArgument(argumentBuilder) + .build() + ) + } + + /** + * Add a new presence flag argument to this command + * + * @param name name of the flag + * @param aliases flag aliases + * @param description description of the flag + * @return this mutable builder + * @since 1.4.0 + */ + public fun flag( + name: String, + aliases: Array = emptyArray(), + description: Description = Description.empty(), + ): MutableCommandBuilder = mutate { + it.flag( + this.commandManager.flagBuilder(name) + .withAliases(*aliases) + .withDescription(description) + .build() + ) + } }