Interface ValueParser<T>
- All Known Subinterfaces:
ResourceKeyedValueParameter<T>
,ValueParameter<T>
,ValueParameter.Simple<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
-
Method Summary
Modifier and TypeMethodDescriptiondefault List<ClientCompletionType>
Provides a hint to the client completion engine what sort of input(s) the client should expect.parseValue
(Parameter.Key<? super T> parameterKey, ArgumentReader.Mutable reader, CommandContext.Builder context) Gets the value for the parameter.
-
Method Details
-
parseValue
Optional<? extends T> parseValue(Parameter.Key<? super T> parameterKey, ArgumentReader.Mutable reader, CommandContext.Builder context) throws ArgumentParseException Gets the value for the parameter. This may return more than one value by adding additional values to the suppliedCommandContext.Builder
.This should have no side effects on anything except on the state of the
ArgumentReader
and, in rare cases, theCommandContext.Builder
.This element may return nothing in the form of an empty optional. This indicates that a parse succeeded, but no meaningful value was returned, for example, the argument must be passed but it's not necessary for the associated
CommandExecutor
to know what the result of the parse was. TheCommandContext.Builder
may be updated in this case.While the
CommandContext.Builder
is provided, in general, you do not need to add the parsed value to it yourself, instead preferring to return your parsed value. It is permissible, however, to add additional information to the context should it be required.The
Cause
of this parse is provided in theCommandContext.Builder
.- Parameters:
parameterKey
- TheParameter.Key
of the parameter being parsedreader
- TheArgumentReader
that contains the unparsed argumentscontext
- TheCommandContext
containing the state about this command- Returns:
- Returns the value(s)
- Throws:
ArgumentParseException
- if a parameter could not be parsed
-
clientCompletionType
Provides a hint to the client completion engine what sort of input(s) the client should expect.Multiple elements can be placed here for multi part parsers - that is, parsers that call parse methods on the
ArgumentReader.Mutable
more than once. However, it is recommended that you consider splitting your parsers up to consume one element at any time, any completions you provide may not be provided to the client if you do so.Returning an empty list does not infer that the element will not be displayed, rather, an empty list infers that the command system will decide. Custom parsers will default to a single
ClientCompletionTypes.STRING
. Be aware, providing a non-string type here may cause your completions to be ignored.If you wish to hide this element from client completion completely, return a
List
with a singleClientCompletionTypes.NONE
.Remember that anything supplied here is a hint. It is possible that this hint will be ignored in some scenarios, particularly if this parser is one of many supplied to
Parameter.Value
.- Returns:
- The
ClientCompletionType
s to use on the client.
-