Class ListValueOptionParser<T>

All Implemented Interfaces:
OptionParser<T>
Direct Known Subclasses:
MaybeListValueOptionParser

public class ListValueOptionParser<T> extends AbstractOptionParser<T>
An options parser that requires the values to be a non-whitespace separated list

So for example --name foo,bar would be treated as the values foo and bar passed to the --name option. This parser differs from the StandardOptionParser in that the standard parser would treat foo,bar as a single value passed to the name option. This parser expects that the list it receives contains the correct number of items for the arity of the option, or an exact multiple thereof and if not produces an error

You can also omit the whitespace between the name and the value list when using a single character name of the option similar to how the ClassicGetOptParser works. For example -nfoo,bar is equivalent to our previous example assuming that -n is an alternative name for the same option as --name.

The default separator for values is , but this can be configured as desired.

  • Field Details

    • DEFAULT_SEPARATOR

      private static final char DEFAULT_SEPARATOR
      See Also:
    • separator

      private final char separator
  • Constructor Details

    • ListValueOptionParser

      public ListValueOptionParser()
    • ListValueOptionParser

      public ListValueOptionParser(char separator)
  • Method Details

    • getValues

      protected final List<String> getValues(String list)
    • parseOptions

      public ParseState<T> parseOptions(org.apache.commons.collections4.iterators.PeekingIterator<String> tokens, ParseState<T> state, 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