@@ -35,14 +35,15 @@ import org.incendo.cloud.key.CloudKey
3535import org.incendo.cloud.kotlin.extension.command
3636import org.incendo.cloud.kotlin.extension.senderType
3737import org.incendo.cloud.parser.ParserDescriptor
38+ import org.incendo.cloud.parser.flag.CommandFlag
3839import org.incendo.cloud.permission.Permission
3940import kotlin.reflect.KClass
4041
4142/* *
4243 * A mutable [Command.Builder] wrapper, providing functions to assist in creating commands using the
4344 * Kotlin builder DSL style
4445 *
45- * @property commandBuilder the command builder the mutate
46+ * @property commandBuilder the command builder to mutate
4647 * @property commandManager the command manager which will own this command
4748 * @constructor Create a new [MutableCommandBuilder]
4849 */
@@ -361,6 +362,16 @@ public class MutableCommandBuilder<C : Any>(
361362 component : CommandComponent <C >
362363 ): MutableCommandBuilder <C > = mutate { it.argument(component) }
363364
365+ /* *
366+ * Adds a new component to this command
367+ *
368+ * @param component component to add
369+ * @return this mutable builder
370+ */
371+ public fun <T > argument (
372+ component : CommandComponent .Builder <C , T >
373+ ): MutableCommandBuilder <C > = mutate { it.argument(component) }
374+
364375 /* *
365376 * Adds a new component to this command
366377 *
@@ -393,11 +404,7 @@ public class MutableCommandBuilder<C : Any>(
393404 name : String ,
394405 parser : ParserDescriptor <C , T >,
395406 mutator : CommandComponent .Builder <C , T >.() -> Unit = {}
396- ): MutableCommandBuilder <C > = mutate {
397- it.argument(
398- CommandComponent .builder(name, parser).also (mutator)
399- )
400- }
407+ ): MutableCommandBuilder <C > = argument(CommandComponent .builder(name, parser).also (mutator))
401408
402409 /* *
403410 * Adds a new component to this command
@@ -411,11 +418,7 @@ public class MutableCommandBuilder<C : Any>(
411418 name : String ,
412419 parser : ParserDescriptor <C , T >,
413420 mutator : CommandComponent .Builder <C , T >.() -> Unit = {}
414- ): MutableCommandBuilder <C > = mutate {
415- it.argument(
416- CommandComponent .builder(name, parser).optional().also (mutator)
417- )
418- }
421+ ): MutableCommandBuilder <C > = argument(CommandComponent .builder(name, parser).optional().also (mutator))
419422
420423 /* *
421424 * Adds a new component to this command
@@ -429,11 +432,7 @@ public class MutableCommandBuilder<C : Any>(
429432 name : CloudKey <T >,
430433 parser : ParserDescriptor <C , T >,
431434 mutator : CommandComponent .Builder <C , T >.() -> Unit = {}
432- ): MutableCommandBuilder <C > = mutate {
433- it.argument(
434- CommandComponent .builder(name, parser).also (mutator)
435- )
436- }
435+ ): MutableCommandBuilder <C > = argument(CommandComponent .builder(name, parser).also (mutator))
437436
438437 /* *
439438 * Adds a new component to this command
@@ -447,11 +446,7 @@ public class MutableCommandBuilder<C : Any>(
447446 name : CloudKey <T >,
448447 parser : ParserDescriptor <C , T >,
449448 mutator : CommandComponent .Builder <C , T >.() -> Unit = {}
450- ): MutableCommandBuilder <C > = mutate {
451- it.argument(
452- CommandComponent .builder(name, parser).optional().also (mutator)
453- )
454- }
449+ ): MutableCommandBuilder <C > = argument(CommandComponent .builder(name, parser).optional().also (mutator))
455450
456451 /* *
457452 * Add a new argument to this command
@@ -461,7 +456,7 @@ public class MutableCommandBuilder<C : Any>(
461456 */
462457 public fun argument (
463458 componentSupplier : () -> CommandComponent <C >
464- ): MutableCommandBuilder <C > = mutate { it. argument(componentSupplier()) }
459+ ): MutableCommandBuilder <C > = argument(componentSupplier())
465460
466461 /* *
467462 * Add a new argument to this command
@@ -481,7 +476,7 @@ public class MutableCommandBuilder<C : Any>(
481476 */
482477 public fun optional (
483478 componentSupplier : () -> CommandComponent .Builder <C , * >
484- ): MutableCommandBuilder <C > = mutate { it. optional(componentSupplier()) }
479+ ): MutableCommandBuilder <C > = optional(componentSupplier())
485480
486481 /* *
487482 * Add a new literal argument to this command
@@ -507,6 +502,15 @@ public class MutableCommandBuilder<C : Any>(
507502 it.handler(handler)
508503 }
509504
505+ /* *
506+ * Set the [CommandExecutionHandler] for this builder
507+ *
508+ * @param handler command execution handler
509+ * @return this mutable builder
510+ */
511+ public fun futureHandler (handler : CommandExecutionHandler .FutureCommandExecutionHandler <C >): MutableCommandBuilder <C > =
512+ mutate { it.futureHandler(handler) }
513+
510514 /* *
511515 * Sets a new command execution handler that invokes the given {@code handler} before the current
512516 * {@link #handler() handler}.
@@ -535,22 +539,48 @@ public class MutableCommandBuilder<C : Any>(
535539 * @param name name of the flag
536540 * @param aliases flag aliases
537541 * @param description description of the flag
538- * @param componentSupplier component supplier for the flag
542+ * @param parser parser for the flag
539543 * @param <T> the component value type
540544 * @return this mutable builder
541545 */
542546 public fun <T > flag (
543547 name : String ,
544548 aliases : Array <String > = emptyArray(),
545549 description : Description = Description .empty(),
546- componentSupplier : () -> TypedCommandComponent <C , T >
550+ parser : ParserDescriptor <C , T >
551+ ): MutableCommandBuilder <C > = mutate {
552+ it.flag(
553+ this .commandManager
554+ .flagBuilder(name)
555+ .withAliases(* aliases)
556+ .withDescription(description)
557+ .withComponent(parser)
558+ .build()
559+ )
560+ }
561+
562+ /* *
563+ * Add a new flag component to this command
564+ *
565+ * @param name name of the flag
566+ * @param aliases flag aliases
567+ * @param description description of the flag
568+ * @param builderModifier flag builder modifier
569+ * @param T the component value type
570+ * @return this mutable builder
571+ */
572+ public fun <T > flag (
573+ name : String ,
574+ aliases : Array <String > = emptyArray(),
575+ description : Description = Description .empty(),
576+ builderModifier : CommandFlag .Builder <C , Void >.() -> CommandFlag .Builder <C , T >
547577 ): MutableCommandBuilder <C > = mutate {
548578 it.flag(
549579 this .commandManager
550580 .flagBuilder(name)
551581 .withAliases(* aliases)
552582 .withDescription(description)
553- .withComponent(componentSupplier() )
583+ .builderModifier( )
554584 .build()
555585 )
556586 }
0 commit comments