Package redempt.ordinate.builder
Class CommandBuilder<T,B extends CommandBuilder<T,B>>
java.lang.Object
redempt.ordinate.builder.CommandBuilder<T,B>
- Type Parameters:
T
- The sender typeB
- The type of the builder itself
Builds a command, provided by
CommandManager
-
Field Summary
Modifier and TypeFieldDescriptionprotected ComponentFactory<T>
protected CommandManager<T>
protected CommandPipeline<T>
-
Constructor Summary
ConstructorDescriptionCommandBuilder
(String[] names, CommandManager<T> manager, BuilderOptions<T> options, CommandBuilderFactory<T, B> builderFactory) -
Method Summary
Modifier and TypeMethodDescriptionAdds a new argument to the commandAdds a new boolean flag to the command, which will be passed as true if present in the command when run and false otherwisebuild()
<V> B
consumingArg
(Class<V> type, String name) Adds a new consuming argument to the command.<V> B
consumingArg
(Class<V> type, String name, boolean optional, Function<CommandContext<T>, V> defaultValue) Adds a new consuming argument to the command.handler
(Consumer<CommandArguments<T>> handler) Assigns a handler that will be run when the command is executedSets the help message of the commandRemoves the auto-generated help subcommand<V> B
optionalArg
(Class<V> type, String name, Function<CommandContext<T>, V> defaultValue) Adds a new optional argument to the commandMarks the command as post-argument, meaning it will be positioned after the arguments of its parent and will be able to access those argumentsregister()
Registers the command.subcommand
(String[] names, Consumer<B> consumer) Creates a subcommand for the commandsubcommand
(String name, Consumer<B> consumer) Creates a subcommand for the command
-
Field Details
-
pipeline
-
manager
-
componentFactory
-
deferred
-
-
Constructor Details
-
CommandBuilder
public CommandBuilder(String[] names, CommandManager<T> manager, BuilderOptions<T> options, CommandBuilderFactory<T, B> builderFactory)
-
-
Method Details
-
help
Sets the help message of the command- Parameters:
help
- The help message- Returns:
- Itself
-
arg
Adds a new argument to the command- Parameters:
type
- The type of the argumentname
- The name of the argument- Returns:
- Itself
-
consumingArg
public <V> B consumingArg(Class<V> type, String name, boolean optional, Function<CommandContext<T>, V> defaultValue) Adds a new consuming argument to the command. Consuming arguments take all the remaining arguments in the command and parse them as a single string.- Type Parameters:
V
- The argument type- Parameters:
type
- The type of the argumentname
- The name of the argumentoptional
- Whether the argument should be optionaldefaultValue
- The default value if no value is provided- Returns:
- Itself
-
consumingArg
Adds a new consuming argument to the command. Consuming arguments take all the remaining arguments in the command and parse them as a single string.- Type Parameters:
V
- The argument type- Parameters:
type
- The type of the argumentname
- The name of the argument- Returns:
- Itself
-
optionalArg
Adds a new optional argument to the command- Type Parameters:
V
- The argument type- Parameters:
type
- The type of the argumentname
- The name of the argumentdefaultValue
- The default value of the argument, pass null for no default- Returns:
- Itself
-
subcommand
Creates a subcommand for the command- Parameters:
names
- The names of the subcommandconsumer
- A function which will mutate the created builder, after which its command will be added as a child of this one- Returns:
- Itself
-
subcommand
Creates a subcommand for the command- Parameters:
name
- The names of the subcommandconsumer
- A function which will mutate the created builder, after which its command will be added as a child of this one- Returns:
- Itself
-
noHelpSubcommand
Removes the auto-generated help subcommand- Returns:
- Itself
-
handler
Assigns a handler that will be run when the command is executed- Parameters:
handler
- The handler- Returns:
- Itself
-
boolFlag
Adds a new boolean flag to the command, which will be passed as true if present in the command when run and false otherwise- Parameters:
names
- The names of the flag, must all start with a dash- Returns:
- Itself
-
postArgument
Marks the command as post-argument, meaning it will be positioned after the arguments of its parent and will be able to access those arguments- Returns:
- Itself
-
build
-
register
Registers the command. Do not call on subcommands.- Returns:
- The built command
-