Module com.github.rvesse.airline
Class GreedyClassicGetOptParser<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.ClassicGetOptParser<T>
-
- com.github.rvesse.airline.parser.options.GreedyClassicGetOptParser<T>
-
- Type Parameters:
T
- Command type
- All Implemented Interfaces:
OptionParser<T>
public class GreedyClassicGetOptParser<T> extends ClassicGetOptParser<T>
Greedy variant of theClassicGetOptParser
that allows consuming values that could otherwise be treated as options in their own right.For example consider a command that defines options
-a
,-b
and-c
where-b
takes a value (i.e. {code arity = 1}) and the others are flag options. With that definition a user can provide the options as-abc
and that would result in the-a
flag being set and the value of-b
set to-c
.However an input of
-acbfoo
would set the-a
and-c
flags while setting the value of-b
tofoo
. If you prefer non-greedy behaviour use theClassicGetOptParser
instead.- Since:
- 2.8.2
-
-
Constructor Summary
Constructors Constructor Description GreedyClassicGetOptParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 option-
Methods inherited from class com.github.rvesse.airline.parser.options.ClassicGetOptParser
parseOptions
-
Methods inherited from class com.github.rvesse.airline.parser.options.AbstractOptionParser
findOption, findOption, hasShortNamePrefix, noValueForOption
-
Methods inherited from class com.github.rvesse.airline.parser.AbstractParser
getTypeConverter
-
-
-
-
Method Detail
-
isSeparatorOrOption
protected boolean isSeparatorOrOption(ParseState<T> state, java.util.List<OptionMetadata> allowedOptions, java.lang.String argsSeparator, boolean shortForm, java.lang.String peekedToken)
Description copied from class:AbstractOptionParser
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.
- Overrides:
isSeparatorOrOption
in classAbstractOptionParser<T>
- 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
-
-