Class ClassicGetOptParser<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    OptionParser<T>
    Direct Known Subclasses:
    GreedyClassicGetOptParser

    public class ClassicGetOptParser<T>
    extends AbstractOptionParser<T>
    An options parsing that parses options given in classic get-opt style where multiple options may be concatenated together, potentially including a value for the last option in the concatenation.

    This is the default variant of the parser used by default configuration and since 2.8.2 was updated to be non-greedy in its value consumption for arity = 1 options. For the old greedy behaviour please use GreedyClassicGetOptParser instead.

    For example consider a command that defines options -a, -b and -c where -b takes a value (i.e. arity = 1) and the others are flag options. With that definition a user can provide the options as -abc and that would result in an error because the c is considered an option and not a value for -b resulting in a ParseOptionMissingValueException being generated.

    However an input of -acbfoo would set the -a and -c flags while setting the value of -b to foo.

    • Constructor Detail

      • ClassicGetOptParser

        public ClassicGetOptParser()
    • Method Detail

      • 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: OptionParser
        Parses one/more options from the token stream
        Parameters:
        tokens - Tokens
        state - Current parser state
        allowedOptions - Allowed options at this point of the parsing
        Returns:
        New parser state, may return null if this parser could not parse the next token as an option