public class MaybeListValueOptionParser<T> extends ListValueOptionParser<T>
--name value
but which allows for the values to be a non-whitespace separated list
This is less strict than ListValueOptionParser which requires that values be non-whitespace separated
So for example --name foo,bar would be treated as the values foo and bar 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 Arguments or DefaultOption 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 treat foo,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 error
You 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 and Description |
|---|
MaybeListValueOptionParser() |
MaybeListValueOptionParser(char separator) |
| Modifier and Type | Method and 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<String> tokens,
ParseState<T> state,
List<OptionMetadata> allowedOptions)
Parses one/more options from the token stream
|
getValuesfindOption, findOption, hasShortNamePrefix, isSeparatorOrOption, noValueForOptiongetTypeConverterpublic MaybeListValueOptionParser()
public MaybeListValueOptionParser(char separator)
public ParseState<T> parseOptions(org.apache.commons.collections4.iterators.PeekingIterator<String> tokens, ParseState<T> state, List<OptionMetadata> allowedOptions)
OptionParserparseOptions in interface OptionParser<T>parseOptions in class ListValueOptionParser<T>tokens - Tokensstate - Current parser stateallowedOptions - Allowed options at this point of the parsingnull if this parser could
not parse the next token as an optionprotected boolean canGreedySearch(ParseState<T> state)
state - Parser StateCopyright © 2012–2022. All rights reserved.