Package kboyle.oktane.core
Class CommandHandler<CONTEXT extends CommandContext>
java.lang.Object
kboyle.oktane.core.CommandHandler<CONTEXT>
- Type Parameters:
CONTEXT- The type of context that's used in commands.
The entry point for executing commands.
CommandHandler.<YourContextType>builder()
.withModule(YourCommandModule.class)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCommandHandler.Builder<CONTEXT extends CommandContext>A builder for theCommandHandler. -
Method Summary
Modifier and TypeMethodDescriptionstatic <CONTEXT extends CommandContext>
CommandHandler.Builder<CONTEXT>builder()Creates a new builder for theCommandHandler.commands()reactor.core.publisher.Mono<Result>Tries to execute a command for the given input, checking whether or not the input starts with a prefix.reactor.core.publisher.Mono<Result>Tries to execute a command for the given input at the given index (does not check for prefixes).com.google.common.collect.ImmutableList<CommandModule>modules()Gets thePrefixHandlerthat thisCommandHandleris using.
-
Method Details
-
builder
Creates a new builder for theCommandHandler.- Returns:
- A new
CommandHandler.Builder.
-
execute
Tries to execute a command for the given input, checking whether or not the input starts with a prefix.- Parameters:
input- The user input to parse.context- TheCommandContextto pass into execution.- Returns:
- The result of execution.
- Throws:
NullPointerException- wheninputis null.NullPointerException- whencontextis null.
-
execute
Tries to execute a command for the given input at the given index (does not check for prefixes).- Parameters:
input- The user input to parse.context- TheCommandContextto pass into execution.startIndex- The index to start parsing theinputfrom.- Returns:
- The result of execution.
- Throws:
NullPointerException- wheninputis null.NullPointerException- whencontextis null.IllegalStateException- whenstartIndex< 0.IllegalStateException- whenstartIndex>input.length().
-
modules
- Returns:
- All of the top level
CommandModules that belong to theCommandHandler.
-
flattenModules
- Returns:
- Recursively gets all top level
CommandModules and their children that belong to theCommandHandler.
-
commands
- Returns:
- All of the
Commands that belong to theCommandHandler.
-
prefixHandler
Gets thePrefixHandlerthat thisCommandHandleris using.- Returns:
- The
PrefixHandler.
-