Class MaybeListValueOptionParser<T>
- java.lang.Object
-
- com.github.rvesse.airline.parser.AbstractParser<T>
-
- com.github.rvesse.airline.parser.options.AbstractOptionParser<T>
-
- com.github.rvesse.airline.parser.options.ListValueOptionParser<T>
-
- com.github.rvesse.airline.parser.options.MaybeListValueOptionParser<T>
-
- All Implemented Interfaces:
OptionParser<T>
- Direct Known Subclasses:
GreedyMaybeListValueOptionParser
public class MaybeListValueOptionParser<T> extends ListValueOptionParser<T>
An options parser that expects the name and value(s) to be white space separated e.g.--name value
but which allows for the values to be a non-whitespace separated listThis is less strict than
ListValueOptionParser
which requires that values be non-whitespace separatedSo for example
--name foo,bar
would be treated as the valuesfoo
andbar
passed to the--name
option. Equally--name foo bar
would do the same thing.Note that this parser is non-greedy so if the command also uses
This parser differs from theArguments
orDefaultOption
then it will stop as soon as it sees enough values to satisfy the arity of the option it is parsing.StandardOptionParser
in that the standard parser would treatfoo,bar
as a single value passed to the name option. This parser expects that the list it receives contains the correct number of items for the arity of the option, or an exact multiple thereof and if not produces an errorYou can also omit the whitespace between the name and the value list when using a single character name of the option similar to how the
ClassicGetOptParser
works. For example-nfoo,bar
is equivalent to our previous example assuming that-n
is an alternative name for the same option as--name
.The default separator for values is
,
but this can be configured as desired.
-
-
Constructor Summary
Constructors Constructor Description MaybeListValueOptionParser()
MaybeListValueOptionParser(char separator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canGreedySearch(ParseState<T> state)
Gets whether we can do a greedy search for list value(s)ParseState<T>
parseOptions(org.apache.commons.collections4.iterators.PeekingIterator<java.lang.String> tokens, ParseState<T> state, java.util.List<OptionMetadata> allowedOptions)
Parses one/more options from the token stream-
Methods inherited from class com.github.rvesse.airline.parser.options.ListValueOptionParser
getValues
-
Methods inherited from class com.github.rvesse.airline.parser.options.AbstractOptionParser
findOption, findOption, hasShortNamePrefix, isSeparatorOrOption, noValueForOption
-
Methods inherited from class com.github.rvesse.airline.parser.AbstractParser
getTypeConverter
-
-
-
-
Method Detail
-
parseOptions
public ParseState<T> parseOptions(org.apache.commons.collections4.iterators.PeekingIterator<java.lang.String> tokens, ParseState<T> state, java.util.List<OptionMetadata> allowedOptions)
Description copied from interface:OptionParser
Parses one/more options from the token stream- Specified by:
parseOptions
in interfaceOptionParser<T>
- Overrides:
parseOptions
in classListValueOptionParser<T>
- Parameters:
tokens
- Tokensstate
- Current parser stateallowedOptions
- Allowed options at this point of the parsing- Returns:
- New parser state, may return
null
if this parser could not parse the next token as an option
-
canGreedySearch
protected boolean canGreedySearch(ParseState<T> state)
Gets whether we can do a greedy search for list value(s)- Parameters:
state
- Parser State- Returns:
- True if a greedy search is permitted, false otherwise
-
-