Module com.github.rvesse.airline
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
public abstract class AbstractOptionParser<T> extends AbstractParser<T> implements OptionParser<T>
Abstract option parser that provides some useful helper methods to derived classes
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
SHORT_OPTIONS_PREFIX
-
Constructor Summary
Constructors Constructor Description AbstractOptionParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected OptionMetadata
findOption(ParseState<T> state, java.util.List<OptionMetadata> options, java.lang.String name)
Tries to find an option with the given nameprotected OptionMetadata
findOption(ParseState<T> state, java.util.List<OptionMetadata> options, java.lang.String name, OptionMetadata defaultValue)
Tries to find an option with the given nameprotected boolean
hasShortNamePrefix(java.lang.String name)
Return true if the option has a short name prefix i.e.protected boolean
isSeparatorOrOption(ParseState<T> state, java.util.List<OptionMetadata> allowedOptions, java.lang.String argsSeparator, boolean shortForm, java.lang.String peekedToken)
Checks whether the next value is an arguments separator or optionprotected void
noValueForOption(ParseState<T> state, OptionMetadata option)
Reports that no/insufficient values were provided for an option-
Methods inherited from class com.github.rvesse.airline.parser.AbstractParser
getTypeConverter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.rvesse.airline.parser.options.OptionParser
parseOptions
-
-
-
-
Method Detail
-
findOption
protected final OptionMetadata findOption(ParseState<T> state, java.util.List<OptionMetadata> options, java.lang.String name)
Tries to find an option with the given name- Parameters:
state
- Current parser stateoptions
- Allowed optionsname
- Name- Returns:
- Option if found,
null
otherwise
-
findOption
protected final OptionMetadata findOption(ParseState<T> state, java.util.List<OptionMetadata> options, java.lang.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,
defaultValue
otherwise
-
hasShortNamePrefix
protected boolean hasShortNamePrefix(java.lang.String name)
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
protected void noValueForOption(ParseState<T> state, OptionMetadata option)
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, java.util.List<OptionMetadata> allowedOptions, java.lang.String argsSeparator, boolean shortForm, java.lang.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, iftrue
only consider the first character ofpeekedToken
peekedToken
- 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
-
-