Class CommandLine

  • All Implemented Interfaces:
    java.io.Serializable

    public class CommandLine
    extends java.lang.Object
    implements java.io.Serializable
    Represents list of arguments parsed against a Options descriptor.

    It allows querying of a boolean hasOption(String optionName), in addition to retrieving the getOptionValue(String optionName) for options requiring arguments.

    Additionally, any left-over or unrecognized arguments, are available for further processing.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CommandLine.Builder
      A nested builder class to create CommandLine instance using descriptive methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> args
      The unrecognized options/arguments
      private java.util.function.Consumer<Option> deprecatedHandler
      The deprecated option handler.
      private java.util.List<Option> options
      The processed options
      private static long serialVersionUID
      The serial version UID.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CommandLine()
      Creates a command line.
      private CommandLine​(java.util.List<java.lang.String> args, java.util.List<Option> options, java.util.function.Consumer<Option> deprecatedHandler)
      Creates a command line.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void addArg​(java.lang.String arg)
      Adds left-over unrecognized option/argument.
      protected void addOption​(Option option)
      Adds an option to the command line.
      static CommandLine.Builder builder()
      Creates a new builder.
      private java.lang.String first​(java.lang.String[] values)
      Gets the first element or null if values is null.
      private <T> T get​(java.util.function.Supplier<T> supplier)  
      java.util.List<java.lang.String> getArgList()
      Gets any left-over non-recognized options and arguments.
      java.lang.String[] getArgs()
      Gets any left-over non-recognized options and arguments.
      int getOptionCount​(char optionChar)
      Gets the number of times this option appears in the command line
      int getOptionCount​(java.lang.String optionName)
      Gets the number of times this option appears in the command line
      int getOptionCount​(Option option)
      Gets the number of times this option appears in the command line.
      java.lang.Object getOptionObject​(char optionChar)
      Deprecated.
      due to System.err message; use getParsedOptionValue(char) instead.
      java.lang.Object getOptionObject​(java.lang.String optionName)
      Deprecated.
      due to System.err message; use getParsedOptionValue(String) instead.
      java.util.Properties getOptionProperties​(java.lang.String optionName)
      Gets the map of values associated to the option.
      java.util.Properties getOptionProperties​(Option option)
      Gets the map of values associated to the option.
      Option[] getOptions()
      Gets an array of the processed Options.
      java.lang.String getOptionValue​(char optionChar)
      Gets the first argument, if any, of this option.
      java.lang.String getOptionValue​(char optionChar, java.lang.String defaultValue)
      Gets the argument, if any, of an option.
      java.lang.String getOptionValue​(char optionChar, java.util.function.Supplier<java.lang.String> defaultValue)
      Gets the argument, if any, of an option.
      java.lang.String getOptionValue​(java.lang.String optionName)
      Gets the first argument, if any, of this option.
      java.lang.String getOptionValue​(java.lang.String optionName, java.lang.String defaultValue)
      Gets the first argument, if any, of an option.
      java.lang.String getOptionValue​(java.lang.String optionName, java.util.function.Supplier<java.lang.String> defaultValue)
      Gets the first argument, if any, of an option.
      java.lang.String getOptionValue​(Option option)
      Gets the first argument, if any, of this option.
      java.lang.String getOptionValue​(OptionGroup optionGroup)
      Gets the first argument, if any, of this option group.
      java.lang.String getOptionValue​(OptionGroup optionGroup, java.lang.String defaultValue)
      Gets the first argument, if any, of an option group.
      java.lang.String getOptionValue​(OptionGroup optionGroup, java.util.function.Supplier<java.lang.String> defaultValue)
      Gets the first argument, if any, of an option group.
      java.lang.String getOptionValue​(Option option, java.lang.String defaultValue)
      Gets the first argument, if any, of an option.
      java.lang.String getOptionValue​(Option option, java.util.function.Supplier<java.lang.String> defaultValue)
      Gets the first argument, if any, of an option.
      java.lang.String[] getOptionValues​(char optionChar)
      Gets the array of values, if any, of an option.
      java.lang.String[] getOptionValues​(java.lang.String optionName)
      Gets the array of values, if any, of an option.
      java.lang.String[] getOptionValues​(Option option)
      Gets the array of values, if any, of an option.
      java.lang.String[] getOptionValues​(OptionGroup optionGroup)
      Gets the array of values, if any, of an option group.
      <T> T getParsedOptionValue​(char optionChar)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(char optionChar, java.util.function.Supplier<T> defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(char optionChar, T defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(java.lang.String optionName)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(java.lang.String optionName, java.util.function.Supplier<T> defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(java.lang.String optionName, T defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(Option option)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(OptionGroup optionGroup)
      Gets a version of this OptionGroup converted to a particular type.
      <T> T getParsedOptionValue​(OptionGroup optionGroup, java.util.function.Supplier<T> defaultValue)
      Gets a version of this OptionGroup converted to a particular type.
      <T> T getParsedOptionValue​(OptionGroup optionGroup, T defaultValue)
      Gets a version of this OptionGroup converted to a particular type.
      <T> T getParsedOptionValue​(Option option, java.util.function.Supplier<T> defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T getParsedOptionValue​(Option option, T defaultValue)
      Gets a version of this Option converted to a particular type.
      <T> T[] getParsedOptionValues​(char optionChar)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(char optionChar, java.util.function.Supplier<T[]> defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(char optionChar, T[] defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(java.lang.String optionName)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(java.lang.String optionName, java.util.function.Supplier<T[]> defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(java.lang.String optionName, T[] defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(Option option)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(OptionGroup optionGroup)
      Gets a version of this OptionGroup converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(OptionGroup optionGroup, java.util.function.Supplier<T[]> defaultValue)
      Gets a version of this OptionGroup converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(OptionGroup optionGroup, T[] defaultValue)
      Gets a version of this OptionGroup converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(Option option, java.util.function.Supplier<T[]> defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      <T> T[] getParsedOptionValues​(Option option, T[] defaultValue)
      Gets a version of this Option converted to an array of a particular type.
      private void handleDeprecated​(Option option)
      Handles deprecated options.
      boolean hasOption​(char optionChar)
      Tests to see if an option has been set.
      boolean hasOption​(java.lang.String optionName)
      Tests to see if an option has been set.
      boolean hasOption​(Option option)
      Tests to see if an option has been set.
      boolean hasOption​(OptionGroup optionGroup)
      Tests to see if an option has been set.
      java.util.Iterator<Option> iterator()
      Returns an iterator over the Option members of CommandLine.
      private void processPropertiesFromValues​(java.util.Properties props, java.util.List<java.lang.String> values)
      Parses a list of values as properties.
      private Option resolveOption​(java.lang.String optionName)
      Retrieves the option object given the long or short option as a String
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        The serial version UID.
        See Also:
        Constant Field Values
      • args

        private final java.util.List<java.lang.String> args
        The unrecognized options/arguments
      • options

        private final java.util.List<Option> options
        The processed options
      • deprecatedHandler

        private final transient java.util.function.Consumer<Option> deprecatedHandler
        The deprecated option handler.

        If you want to serialize this field, use a serialization proxy.

    • Constructor Detail

      • CommandLine

        protected CommandLine()
        Creates a command line.
      • CommandLine

        private CommandLine​(java.util.List<java.lang.String> args,
                            java.util.List<Option> options,
                            java.util.function.Consumer<Option> deprecatedHandler)
        Creates a command line.
    • Method Detail

      • builder

        public static CommandLine.Builder builder()
        Creates a new builder.
        Returns:
        a new builder.
        Since:
        1.7.0
      • addArg

        protected void addArg​(java.lang.String arg)
        Adds left-over unrecognized option/argument.
        Parameters:
        arg - the unrecognized option/argument.
      • addOption

        protected void addOption​(Option option)
        Adds an option to the command line. The values of the option are stored.
        Parameters:
        option - the processed option.
      • first

        private java.lang.String first​(java.lang.String[] values)
        Gets the first element or null if values is null.
        Parameters:
        values - the array to query.
        Returns:
        the first element or null if values is null.
      • get

        private <T> T get​(java.util.function.Supplier<T> supplier)
      • getArgList

        public java.util.List<java.lang.String> getArgList()
        Gets any left-over non-recognized options and arguments.
        Returns:
        remaining items passed in but not parsed as a List.
      • getArgs

        public java.lang.String[] getArgs()
        Gets any left-over non-recognized options and arguments.
        Returns:
        remaining items passed in but not parsed as an array.
      • getOptionCount

        public int getOptionCount​(char optionChar)
        Gets the number of times this option appears in the command line
        Parameters:
        optionChar - the character name of the option.
        Returns:
        Number of times the option is present.
        Since:
        1.11.0
      • getOptionCount

        public int getOptionCount​(Option option)
        Gets the number of times this option appears in the command line.
        Parameters:
        option - the option.
        Returns:
        Number of times the option is present.
        Since:
        1.11.0
      • getOptionCount

        public int getOptionCount​(java.lang.String optionName)
        Gets the number of times this option appears in the command line
        Parameters:
        optionName - the name of the option.
        Returns:
        Number of times the option is present.
        Since:
        1.11.0
      • getOptionObject

        @Deprecated
        public java.lang.Object getOptionObject​(char optionChar)
        Deprecated.
        due to System.err message; use getParsedOptionValue(char) instead.
        Gets the Object type of this Option.
        Parameters:
        optionChar - the name of the option.
        Returns:
        the type of opt.
      • getOptionObject

        @Deprecated
        public java.lang.Object getOptionObject​(java.lang.String optionName)
        Deprecated.
        due to System.err message; use getParsedOptionValue(String) instead.
        Gets the Object type of this Option.
        Parameters:
        optionName - the name of the option.
        Returns:
        the type of this Option.
      • getOptionProperties

        public java.util.Properties getOptionProperties​(Option option)
        Gets the map of values associated to the option. This is convenient for options specifying Java properties like -Dparam1=value1 -Dparam2=value2. All odd numbered values are property keys and even numbered values are property values. If there are an odd number of values the last value is assumed to be a boolean flag and the value is "true".
        Parameters:
        option - name of the option.
        Returns:
        The Properties mapped by the option, never null even if the option doesn't exists.
        Since:
        1.5.0
      • getOptionProperties

        public java.util.Properties getOptionProperties​(java.lang.String optionName)
        Gets the map of values associated to the option. This is convenient for options specifying Java properties like -Dparam1=value1 -Dparam2=value2. The first argument of the option is the key, and the 2nd argument is the value. If the option has only one argument (-Dfoo) it is considered as a boolean flag and the value is "true".
        Parameters:
        optionName - name of the option.
        Returns:
        The Properties mapped by the option, never null even if the option doesn't exists.
        Since:
        1.2
      • getOptions

        public Option[] getOptions()
        Gets an array of the processed Options.
        Returns:
        an array of the processed Options.
      • getOptionValue

        public java.lang.String getOptionValue​(char optionChar)
        Gets the first argument, if any, of this option.
        Parameters:
        optionChar - the character name of the option.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise null.
      • getOptionValue

        public java.lang.String getOptionValue​(char optionChar,
                                               java.lang.String defaultValue)
        Gets the argument, if any, of an option.
        Parameters:
        optionChar - character name of the option
        defaultValue - is the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
      • getOptionValue

        public java.lang.String getOptionValue​(char optionChar,
                                               java.util.function.Supplier<java.lang.String> defaultValue)
        Gets the argument, if any, of an option.
        Parameters:
        optionChar - character name of the option.
        defaultValue - is a supplier for the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
        Since:
        1.7.0
      • getOptionValue

        public java.lang.String getOptionValue​(Option option)
        Gets the first argument, if any, of this option.
        Parameters:
        option - the option.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise null.
        Since:
        1.5.0
      • getOptionValue

        public java.lang.String getOptionValue​(Option option,
                                               java.lang.String defaultValue)
        Gets the first argument, if any, of an option.
        Parameters:
        option - the option.
        defaultValue - is the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
        Since:
        1.5.0
      • getOptionValue

        public java.lang.String getOptionValue​(Option option,
                                               java.util.function.Supplier<java.lang.String> defaultValue)
        Gets the first argument, if any, of an option.
        Parameters:
        option - the option.
        defaultValue - is a supplier for the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
        Since:
        1.7.0
      • getOptionValue

        public java.lang.String getOptionValue​(OptionGroup optionGroup)
        Gets the first argument, if any, of this option group.
        Parameters:
        optionGroup - the option group.
        Returns:
        Value of the argument if option group is selected, and has an argument, otherwise null.
        Since:
        1.9.0
      • getOptionValue

        public java.lang.String getOptionValue​(OptionGroup optionGroup,
                                               java.lang.String defaultValue)
        Gets the first argument, if any, of an option group.
        Parameters:
        optionGroup - the option group.
        defaultValue - is the default value to be returned if the option group is not selected.
        Returns:
        Value of the argument if option group is selected, and has an argument, otherwise defaultValue.
        Since:
        1.9.0
      • getOptionValue

        public java.lang.String getOptionValue​(OptionGroup optionGroup,
                                               java.util.function.Supplier<java.lang.String> defaultValue)
        Gets the first argument, if any, of an option group.
        Parameters:
        optionGroup - the option group.
        defaultValue - is a supplier for the default value to be returned if the option group is not selected.
        Returns:
        Value of the argument if option group is selected, and has an argument, otherwise defaultValue.
        Since:
        1.9.0
      • getOptionValue

        public java.lang.String getOptionValue​(java.lang.String optionName)
        Gets the first argument, if any, of this option.
        Parameters:
        optionName - the name of the option.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise null.
      • getOptionValue

        public java.lang.String getOptionValue​(java.lang.String optionName,
                                               java.lang.String defaultValue)
        Gets the first argument, if any, of an option.
        Parameters:
        optionName - name of the option.
        defaultValue - is the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
      • getOptionValue

        public java.lang.String getOptionValue​(java.lang.String optionName,
                                               java.util.function.Supplier<java.lang.String> defaultValue)
        Gets the first argument, if any, of an option.
        Parameters:
        optionName - name of the option.
        defaultValue - is a supplier for the default value to be returned if the option is not specified.
        Returns:
        Value of the argument if option is set, and has an argument, otherwise defaultValue.
        Since:
        1.7.0
      • getOptionValues

        public java.lang.String[] getOptionValues​(char optionChar)
        Gets the array of values, if any, of an option.
        Parameters:
        optionChar - character name of the option.
        Returns:
        Values of the argument if option is set, and has an argument, otherwise null.
      • getOptionValues

        public java.lang.String[] getOptionValues​(Option option)
        Gets the array of values, if any, of an option.
        Parameters:
        option - the option.
        Returns:
        Values of the argument if option is set, and has an argument, otherwise null.
        Since:
        1.5.0
      • getOptionValues

        public java.lang.String[] getOptionValues​(OptionGroup optionGroup)
        Gets the array of values, if any, of an option group.
        Parameters:
        optionGroup - the option group.
        Returns:
        Values of the argument if option group is selected, and has an argument, otherwise null.
        Since:
        1.9.0
      • getOptionValues

        public java.lang.String[] getOptionValues​(java.lang.String optionName)
        Gets the array of values, if any, of an option.
        Parameters:
        optionName - string name of the option.
        Returns:
        Values of the argument if option is set, and has an argument, otherwise null.
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(char optionChar)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionChar - the name of the option.
        Returns:
        the value parsed into a particular object or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.5.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(char optionChar,
                                          java.util.function.Supplier<T> defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionChar - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(char optionChar,
                                          T defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionChar - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(Option option)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        option - the option.
        Returns:
        the value parsed into a particular object or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.5.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(Option option,
                                          java.util.function.Supplier<T> defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        option - the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(Option option,
                                          T defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        option - the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(OptionGroup optionGroup)
                                   throws ParseException
        Gets a version of this OptionGroup converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionGroup - the option group.
        Returns:
        the value parsed into a particular object or null if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the selected option value into the desired type.
        Since:
        1.9.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(OptionGroup optionGroup,
                                          java.util.function.Supplier<T> defaultValue)
                                   throws ParseException
        Gets a version of this OptionGroup converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionGroup - the option group.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the selected option value into the desired type.
        Since:
        1.9.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(OptionGroup optionGroup,
                                          T defaultValue)
                                   throws ParseException
        Gets a version of this OptionGroup converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionGroup - the option group.
        defaultValue - the default value to return if an option is not selected.
        Returns:
        the value parsed into a particular object or the defaultValue if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.9.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(java.lang.String optionName)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionName - the name of the option.
        Returns:
        the value parsed into a particular object or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.2
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(java.lang.String optionName,
                                          java.util.function.Supplier<T> defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionName - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValue

        public <T> T getParsedOptionValue​(java.lang.String optionName,
                                          T defaultValue)
                                   throws ParseException
        Gets a version of this Option converted to a particular type.
        Type Parameters:
        T - The return type for the method.
        Parameters:
        optionName - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the value parsed into a particular object or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.7.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(char optionChar)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionChar - the name of the option.
        Returns:
        the values parsed into an array of objects or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(char optionChar,
                                             java.util.function.Supplier<T[]> defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionChar - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(char optionChar,
                                             T[] defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionChar - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(Option option)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        option - the option.
        Returns:
        the values parsed into an array of objects or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(Option option,
                                             java.util.function.Supplier<T[]> defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        option - the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(Option option,
                                             T[] defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        option - the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or the defaultValue if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(OptionGroup optionGroup)
                                      throws ParseException
        Gets a version of this OptionGroup converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionGroup - the option group.
        Returns:
        the values parsed into an array of objects or null if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the selected option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(OptionGroup optionGroup,
                                             java.util.function.Supplier<T[]> defaultValue)
                                      throws ParseException
        Gets a version of this OptionGroup converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionGroup - the option group.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or null if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the selected option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(OptionGroup optionGroup,
                                             T[] defaultValue)
                                      throws ParseException
        Gets a version of this OptionGroup converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionGroup - the option group.
        defaultValue - the default value to return if an option is not selected.
        Returns:
        the values parsed into an array of objects or null if no option in the OptionGroup is set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(java.lang.String optionName)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionName - the name of the option.
        Returns:
        the values parsed into an array of objects or null if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(java.lang.String optionName,
                                             java.util.function.Supplier<T[]> defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionName - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or defaultValues if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • getParsedOptionValues

        public <T> T[] getParsedOptionValues​(java.lang.String optionName,
                                             T[] defaultValue)
                                      throws ParseException
        Gets a version of this Option converted to an array of a particular type.
        Type Parameters:
        T - The array type for the return value.
        Parameters:
        optionName - the name of the option.
        defaultValue - the default value to return if opt is not set.
        Returns:
        the values parsed into an array of objects or defaultValues if the option is not set.
        Throws:
        ParseException - if there are problems turning the option value into the desired type.
        Since:
        1.10.0
        See Also:
        PatternOptionBuilder
      • handleDeprecated

        private void handleDeprecated​(Option option)
        Handles deprecated options.
        Parameters:
        option - a deprecated option.
      • hasOption

        public boolean hasOption​(char optionChar)
        Tests to see if an option has been set.
        Parameters:
        optionChar - character name of the option.
        Returns:
        true if set, false if not.
      • hasOption

        public boolean hasOption​(Option option)
        Tests to see if an option has been set.
        Parameters:
        option - the option to check.
        Returns:
        true if set, false if not.
        Since:
        1.5.0
      • hasOption

        public boolean hasOption​(OptionGroup optionGroup)
        Tests to see if an option has been set.
        Parameters:
        optionGroup - the option group to check.
        Returns:
        true if set, false if not.
        Since:
        1.9.0
      • hasOption

        public boolean hasOption​(java.lang.String optionName)
        Tests to see if an option has been set.
        Parameters:
        optionName - Short name of the option.
        Returns:
        true if set, false if not.
      • iterator

        public java.util.Iterator<Option> iterator()
        Returns an iterator over the Option members of CommandLine.
        Returns:
        an Iterator over the processed Option members of this CommandLine.
      • processPropertiesFromValues

        private void processPropertiesFromValues​(java.util.Properties props,
                                                 java.util.List<java.lang.String> values)
        Parses a list of values as properties. All odd numbered values are property keys and even numbered values are property values. If there are an odd number of values the last value is assumed to be a boolean with a value of "true".
        Parameters:
        props - the properties to update.
        values - the list of values to parse.
      • resolveOption

        private Option resolveOption​(java.lang.String optionName)
        Retrieves the option object given the long or short option as a String
        Parameters:
        optionName - short or long name of the option, may be null.
        Returns:
        Canonicalized option.