Add helper method for flags to MutableCommandBuilder

This commit is contained in:
jmp 2021-01-11 16:38:08 -08:00 committed by Alexander Söderberg
parent 47d602fde1
commit 39b94a3df0

View file

@ -475,4 +475,101 @@ public class MutableCommandBuilder<C : Any> {
handler: CommandExecutionHandler<C> handler: CommandExecutionHandler<C>
): MutableCommandBuilder<C> = ): MutableCommandBuilder<C> =
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<String> = emptyArray(),
description: Description = Description.empty(),
argumentSupplier: () -> CommandArgument<C, *>
): MutableCommandBuilder<C> = 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<String> = emptyArray(),
description: Description = Description.empty(),
argument: CommandArgument<C, *>
): MutableCommandBuilder<C> = 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<String> = emptyArray(),
description: Description = Description.empty(),
argumentBuilder: CommandArgument.Builder<C, *>
): MutableCommandBuilder<C> = 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<String> = emptyArray(),
description: Description = Description.empty(),
): MutableCommandBuilder<C> = mutate {
it.flag(
this.commandManager.flagBuilder(name)
.withAliases(*aliases)
.withDescription(description)
.build()
)
}
} }