Class GreedyClassicGetOptParser<T>

  • Type Parameters:
    T - Command type
    All Implemented Interfaces:
    OptionParser<T>

    public class GreedyClassicGetOptParser<T>
    extends ClassicGetOptParser<T>
    Greedy variant of the ClassicGetOptParser 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 to foo. If you prefer non-greedy behaviour use the ClassicGetOptParser instead.

    Since:
    2.8.2
    • Constructor Detail

      • GreedyClassicGetOptParser

        public GreedyClassicGetOptParser()
    • 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 option

        This 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 class AbstractOptionParser<T>
        Parameters:
        state - Parse State
        allowedOptions - Allowed options
        argsSeparator - Arguments separator
        shortForm - Whether to test only for short form, if true only consider the first character of peekedToken
        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