Class AbstractOptionParser<T>
java.lang.Object
com.github.rvesse.airline.parser.AbstractParser<T>
com.github.rvesse.airline.parser.options.AbstractOptionParser<T>
- All Implemented Interfaces:
OptionParser<T>
- Direct Known Subclasses:
AbstractNameValueOptionParser, ClassicGetOptParser, JdbcStyleOptionParser, ListValueOptionParser, MaybePairValueOptionParser, StandardOptionParser
Abstract option parser that provides some useful helper methods to derived classes
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final OptionMetadatafindOption(ParseState<T> state, List<OptionMetadata> options, String name) Tries to find an option with the given nameprotected final OptionMetadatafindOption(ParseState<T> state, List<OptionMetadata> options, String name, OptionMetadata defaultValue) Tries to find an option with the given nameprotected booleanhasShortNamePrefix(String name) Return true if the option has a short name prefix i.e.protected booleanisSeparatorOrOption(ParseState<T> state, List<OptionMetadata> allowedOptions, String argsSeparator, boolean shortForm, String peekedToken) Checks whether the next value is an arguments separator or optionprotected voidnoValueForOption(ParseState<T> state, OptionMetadata option) Reports that no/insufficient values were provided for an optionMethods inherited from class AbstractParser
getTypeConverterMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface OptionParser
parseOptions
-
Field Details
-
SHORT_OPTIONS_PREFIX
-
-
Constructor Details
-
AbstractOptionParser
public AbstractOptionParser()
-
-
Method Details
-
findOption
protected final OptionMetadata findOption(ParseState<T> state, List<OptionMetadata> options, String name) Tries to find an option with the given name- Parameters:
state- Current parser stateoptions- Allowed optionsname- Name- Returns:
- Option if found,
nullotherwise
-
findOption
protected final OptionMetadata findOption(ParseState<T> state, List<OptionMetadata> options, String name, OptionMetadata defaultValue) Tries to find an option with the given name- Parameters:
state- Current parser stateoptions- Allowed optionsname- NamedefaultValue- Default value to return if nothing found- Returns:
- Option if found,
defaultValueotherwise
-
hasShortNamePrefix
Return true if the option has a short name prefix i.e. starts with a single-character. This does not mean that it actually is a short option since definitions of what are considered a short option will vary by concrete implementation- Parameters:
name- Option name- Returns:
- True if a short name prefix, false otherwise
-
noValueForOption
Reports that no/insufficient values were provided for an option- Parameters:
state- Parser stateoption- Option whose value(s) are missing
-
isSeparatorOrOption
protected boolean isSeparatorOrOption(ParseState<T> state, List<OptionMetadata> allowedOptions, String argsSeparator, boolean shortForm, String peekedToken) Checks whether the next value is an arguments separator or optionThis helps option parsers ensure they are not overly greedy when trying to consume options and their values when they should instead be raising an error because no value is provided for an option.
- Parameters:
state- Parse StateallowedOptions- Allowed optionsargsSeparator- Arguments separatorshortForm- Whether to test only for short form, iftrueonly consider the first character ofpeekedTokenpeekedToken- The peeked token to check whether it is the arguments separator or an option- Returns:
- True if the peeked token represents an arguments separator or an option
-