Class CommandFlagParser<C>
- All Implemented Interfaces:
ArgumentParser<C,,Object> ArgumentParser.FutureArgumentParser<C,,Object> SuggestionProvider<C>,SuggestionProviderHolder<C>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumReasons for which flag parsing may failstatic final classFlag parse exceptionNested classes/interfaces inherited from interface org.incendo.cloud.parser.ArgumentParser
ArgumentParser.FutureArgumentParser<C,T> -
Field Summary
FieldsModifier and TypeFieldDescriptionMetadata for the position of the cursor before parsing the last flag's valueMetadata for the last argument that was suggestedstatic final ObjectDummy object that indicates that flags were parsed successfullystatic final CloudKey<Set<CommandFlag<?>>> Metadata for the set of parsed flags, used to detect duplicates. -
Constructor Summary
ConstructorsConstructorDescriptionCommandFlagParser(@NonNull Collection<@NonNull CommandFlag<?>> flags) Creates a new command flag parser. -
Method Summary
Modifier and TypeMethodDescriptionflags()Returns the recognized flags.parseCurrentFlag(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput, @NonNull Executor completionExecutor) Parses command input to figure out what flag is currently being typed at the end of the input queue.parseFuture(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) Returns a future that completes with the result of parsing the givencommandInput.suggestionsFuture(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) Returns a future that completes with the suggestions for the giveninput.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.incendo.cloud.parser.ArgumentParser
flatMap, flatMapSuccess, mapSuccess, suggestionProviderMethods inherited from interface org.incendo.cloud.parser.ArgumentParser.FutureArgumentParser
parse
-
Field Details
-
FLAG_PARSE_RESULT_OBJECT
Dummy object that indicates that flags were parsed successfully -
FLAG_META_KEY
Metadata for the last argument that was suggested -
FLAG_CURSOR_KEY
Metadata for the position of the cursor before parsing the last flag's value -
PARSED_FLAGS
Metadata for the set of parsed flags, used to detect duplicates.
-
-
Constructor Details
-
CommandFlagParser
Creates a new command flag parser.- Parameters:
flags- the flags
-
-
Method Details
-
flags
Returns the recognized flags.- Returns:
- unmodifiable view of flags
-
parseFuture
public @NonNull CompletableFuture<@NonNull ArgumentParseResult<Object>> parseFuture(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) Description copied from interface:ArgumentParserReturns a future that completes with the result of parsing the givencommandInput.This method may be called when a command chain is being parsed for execution (using
CommandExecutor.executeCommand(Object, String)) or when a command is being parsed to provide context for suggestions (usingSuggestionFactory.suggest(Object, String)). It is possible to useCommandContext.isSuggestions()} to see what the purpose of the parsing is. Particular care should be taken when parsing for suggestions, as the parsing method is then likely to be called once for every character written by the command sender.This method should never throw any exceptions under normal circumstances. Instead, if the parsing for some reason cannot be done successfully
ArgumentParseResult.failure(Throwable)orArgumentParseResult.failureFuture(Throwable)should be returned. This then wraps any exception that should be forwarded to the command sender.The parser is assumed to be completely stateless and should not store any information about the command sender or the command context. Instead, information should be stored in the
CommandContext.- Specified by:
parseFuturein interfaceArgumentParser<C,Object> - Specified by:
parseFuturein interfaceArgumentParser.FutureArgumentParser<C,Object> - Parameters:
commandContext- Command contextcommandInput- Command Input- Returns:
- future that completes with the result.
-
parseCurrentFlag
@API(status=STABLE) public @NonNull CompletableFuture<Optional<String>> parseCurrentFlag(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput, @NonNull Executor completionExecutor) Parses command input to figure out what flag is currently being typed at the end of the input queue. If no flag value is being inputted, returnsOptional.empty().
Will consume all but the last element from the input queue.- Parameters:
commandContext- Command contextcommandInput- The input argumentscompletionExecutor- The completion executor- Returns:
- current flag being typed, or
empty()if none is
-
suggestionsFuture
public @NonNull CompletableFuture<Iterable<@NonNull Suggestion>> suggestionsFuture(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) Description copied from interface:SuggestionProviderReturns a future that completes with the suggestions for the giveninput.The
inputparameter contains all sender-provided input that has not yet been consumed by the argument parsers. If the component that the suggestion provider is generating suggestions for consumes multiple tokens the suggestion provider might receive aCommandInputinstance containing multiple tokens.CommandInput.lastRemainingToken()may be used to extract the part of the command that is currently being completed by the command sender.If you don't need to return a future, you can implement
BlockingSuggestionProviderinstead.- Specified by:
suggestionsFuturein interfaceSuggestionProvider<C>- Parameters:
commandContext- the context of the suggestion lookupinput- the current input- Returns:
- the suggestions
-