Class MaybePairValueOptionParser<T>
- All Implemented Interfaces:
OptionParser<T>
--name value but which allows for the values to be a
non-whitespace separated pair
So for example --name foo=bar would be treated as the values
foo and bar passed to the --name option. This parser
would also support --name foo bar and interpret them in the same way
and as such is a convenient hybrid of the StandardOptionParser and
the ListValueOptionParser for cases where you have arity 2 options
that users may either express the two values as separate values or in pair
style.
You can also omit the whitespace between the name and the values 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charprivate final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionparseOptions(org.apache.commons.collections4.iterators.PeekingIterator<String> tokens, ParseState<T> state, List<OptionMetadata> allowedOptions) Parses one/more options from the token streamMethods inherited from class AbstractOptionParser
findOption, findOption, hasShortNamePrefix, isSeparatorOrOption, noValueForOptionMethods inherited from class AbstractParser
getTypeConverter
-
Field Details
-
DEFAULT_SEPARATOR
private static final char DEFAULT_SEPARATOR- See Also:
-
separator
private final char separator
-
-
Constructor Details
-
MaybePairValueOptionParser
public MaybePairValueOptionParser() -
MaybePairValueOptionParser
public MaybePairValueOptionParser(char separator)
-
-
Method Details
-
getValues
-
parseOptions
public ParseState<T> parseOptions(org.apache.commons.collections4.iterators.PeekingIterator<String> tokens, ParseState<T> state, List<OptionMetadata> allowedOptions) Description copied from interface:OptionParserParses one/more options from the token stream- Parameters:
tokens- Tokensstate- Current parser stateallowedOptions- Allowed options at this point of the parsing- Returns:
- New parser state, may return
nullif this parser could not parse the next token as an option
-