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 opt), in addition to retrieving the getOptionValue(String opt) for options requiring arguments.

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

    Version:
    $Revision: 735247 $, $Date: 2009-01-17 00:23:35 -0800 (Sat, 17 Jan 2009) $
    Author:
    bob mcwhirter (bob @ werken.com), James Strachan, John Keyes (john at integralsource.com)
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.util.List getArgList()
      Retrieve any left-over non-recognized options and arguments
      java.lang.String[] getArgs()
      Retrieve any left-over non-recognized options and arguments
      java.lang.Object getOptionObject​(char opt)
      Return the Object type of this Option.
      java.lang.Object getOptionObject​(java.lang.String opt)
      Deprecated.
      due to System.err message.
      java.util.Properties getOptionProperties​(java.lang.String opt)
      Retrieve the map of values associated to the option.
      Option[] getOptions()
      Returns an array of the processed Options.
      java.lang.String getOptionValue​(char opt)
      Retrieve the argument, if any, of this option.
      java.lang.String getOptionValue​(char opt, java.lang.String defaultValue)
      Retrieve the argument, if any, of an option.
      java.lang.String getOptionValue​(java.lang.String opt)
      Retrieve the argument, if any, of this option.
      java.lang.String getOptionValue​(java.lang.String opt, java.lang.String defaultValue)
      Retrieve the argument, if any, of an option.
      java.lang.String[] getOptionValues​(char opt)
      Retrieves the array of values, if any, of an option.
      java.lang.String[] getOptionValues​(java.lang.String opt)
      Retrieves the array of values, if any, of an option.
      java.lang.Object getParsedOptionValue​(java.lang.String opt)
      Return a version of this Option converted to a particular type.
      boolean hasOption​(char opt)
      Query to see if an option has been set.
      boolean hasOption​(java.lang.String opt)
      Query to see if an option has been set.
      java.util.Iterator iterator()
      Returns an iterator over the Option members of CommandLine.
      • Methods inherited from class java.lang.Object

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

      • hasOption

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

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

        public java.lang.Object getOptionObject​(java.lang.String opt)
        Deprecated.
        due to System.err message. Instead use getParsedOptionValue(String)
        Return the Object type of this Option.
        Parameters:
        opt - the name of the option
        Returns:
        the type of this Option
      • getParsedOptionValue

        public java.lang.Object getParsedOptionValue​(java.lang.String opt)
                                              throws ParseException
        Return a version of this Option converted to a particular type.
        Parameters:
        opt - the name of the option
        Returns:
        the value parsed into a particluar object
        Throws:
        ParseException - if there are problems turning the option value into the desired type
        See Also:
        PatternOptionBuilder
      • getOptionObject

        public java.lang.Object getOptionObject​(char opt)
        Return the Object type of this Option.
        Parameters:
        opt - the name of the option
        Returns:
        the type of opt
      • getOptionValue

        public java.lang.String getOptionValue​(java.lang.String opt)
        Retrieve the argument, if any, of this option.
        Parameters:
        opt - 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​(char opt)
        Retrieve the argument, if any, of this option.
        Parameters:
        opt - the character name of the option
        Returns:
        Value of the argument if option is set, and has an argument, otherwise null.
      • getOptionValues

        public java.lang.String[] getOptionValues​(java.lang.String opt)
        Retrieves the array of values, if any, of an option.
        Parameters:
        opt - string 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​(char opt)
        Retrieves the array of values, if any, of an option.
        Parameters:
        opt - character name of the option
        Returns:
        Values of the argument if option is set, and has an argument, otherwise null.
      • getOptionValue

        public java.lang.String getOptionValue​(java.lang.String opt,
                                               java.lang.String defaultValue)
        Retrieve the argument, if any, of an option.
        Parameters:
        opt - 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 opt,
                                               java.lang.String defaultValue)
        Retrieve the argument, if any, of an option.
        Parameters:
        opt - 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.
      • getOptionProperties

        public java.util.Properties getOptionProperties​(java.lang.String opt)
        Retrieve 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:
        opt - name of the option
        Returns:
        The Properties mapped by the option, never null even if the option doesn't exists
        Since:
        1.2
      • getArgs

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

        public java.util.List getArgList()
        Retrieve any left-over non-recognized options and arguments
        Returns:
        remaining items passed in but not parsed as a List.
      • iterator

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