Class MaybePairValueOptionParser<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.MaybePairValueOptionParser<T>
-
- All Implemented Interfaces:
OptionParser<T>
public class MaybePairValueOptionParser<T> extends AbstractOptionParser<T>
An options parser that expects the name and values to be white space separated e.g.--name valuebut which allows for the values to be a non-whitespace separated pairSo for example
--name foo=barwould be treated as the valuesfooandbarpassed to the--nameoption. This parser would also support--name foo barand interpret them in the same way and as such is a convenient hybrid of theStandardOptionParserand theListValueOptionParserfor 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
ClassicGetOptParserworks. For example-nfoo=baris equivalent to our previous example assuming that-nis an alternative name for the same option as--name.The default separator for values is
=but this can be configured as desired.
-
-
Field Summary
Fields Modifier and Type Field Description private static charDEFAULT_SEPARATORprivate charseparator
-
Constructor Summary
Constructors Constructor Description MaybePairValueOptionParser()MaybePairValueOptionParser(char separator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<java.lang.String>getValues(java.lang.String list)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.AbstractOptionParser
findOption, findOption, hasShortNamePrefix, isSeparatorOrOption, noValueForOption
-
Methods inherited from class com.github.rvesse.airline.parser.AbstractParser
getTypeConverter
-
-
-
-
Field Detail
-
DEFAULT_SEPARATOR
private static final char DEFAULT_SEPARATOR
- See Also:
- Constant Field Values
-
separator
private final char separator
-
-
Method Detail
-
getValues
protected final java.util.List<java.lang.String> getValues(java.lang.String list)
-
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: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
-
-