Class AbstractOptionParser<T>

    • Field Detail

      • SHORT_OPTIONS_PREFIX

        private static final java.util.regex.Pattern SHORT_OPTIONS_PREFIX
    • Constructor Detail

      • AbstractOptionParser

        public AbstractOptionParser()
    • 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 state
        options - Allowed options
        name - 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 state
        options - Allowed options
        name - Name
        defaultValue - 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 state
        option - 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 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.

        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