Class ParsedOptions

java.lang.Object
com.aspectran.shell.command.option.ParsedOptions
All Implemented Interfaces:
Serializable

public class ParsedOptions extends Object implements Serializable
Represents list of arguments parsed against a Options descriptor.

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

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

See Also:
  • Constructor Details

    • ParsedOptions

      protected ParsedOptions()
  • Method Details

    • hasOption

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

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

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

      public boolean hasOptions()
      Checks if options exists.
      Returns:
      true if options exists; false otherwise
    • getTypedValue

      public <T> T getTypedValue(Option option) throws OptionParserException
      Return a version of this Option converted to a particular type.
      Type Parameters:
      T - type to attempt to convert to
      Parameters:
      option - the option
      Returns:
      the value parsed into a particular object
      Throws:
      OptionParserException - if there are problems turning the option value into the desired type
    • getTypedValue

      public <T> T getTypedValue(String name) throws OptionParserException
      Return a version of this Option converted to a particular type.
      Type Parameters:
      T - type to attempt to convert to
      Parameters:
      name - the name of the option
      Returns:
      the value parsed into a particular object
      Throws:
      OptionParserException - if there are problems turning the option value into the desired type
    • getTypedValue

      public <T> T getTypedValue(char name) throws OptionParserException
      Return a version of this Option converted to a particular type.
      Type Parameters:
      T - type to attempt to convert to
      Parameters:
      name - the name of the option
      Returns:
      the value parsed into a particular object
      Throws:
      OptionParserException - if there are problems turning the option value into the desired type
    • getValue

      public String getValue(Option option)
      Retrieve the first argument, if any, of this option.
      Parameters:
      option - the name of the option
      Returns:
      the value of the argument if option is set, and has an argument, otherwise null
    • getValue

      public String getValue(String name)
      Retrieve the first argument, if any, of this option.
      Parameters:
      name - the name of the option
      Returns:
      the value of the argument if option is set, and has an argument, otherwise null
    • getValue

      public String getValue(char name)
      Retrieve the first argument, if any, of this option.
      Parameters:
      name - the character name of the option
      Returns:
      the value of the argument if option is set, and has an argument, otherwise null
    • getValues

      @Nullable public String[] getValues(Option option)
      Retrieves the array of values, if any, of an option.
      Parameters:
      option - string name of the option
      Returns:
      the values of the argument if option is set, and has an argument, otherwise null
    • getValues

      public String[] getValues(String name)
      Retrieves the array of values, if any, of an option.
      Parameters:
      name - string name of the option
      Returns:
      the values of the argument if option is set, and has an argument, otherwise null
    • getValues

      public String[] getValues(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
    • getValue

      public String getValue(Option option, String defaultValue)
      Retrieve the first argument, if any, of an option.
      Parameters:
      option - the name of the option
      defaultValue - the default value to be returned if the option is not specified
      Returns:
      the value of the argument if option is set, and has an argument, otherwise defaultValue
    • getValue

      public String getValue(String name, String defaultValue)
      Retrieve the first argument, if any, of an option.
      Parameters:
      name - the name of the option
      defaultValue - the default value to be returned if the option is not specified
      Returns:
      the value of the argument if option is set, and has an argument, otherwise defaultValue
    • getValue

      public String getValue(char name, String defaultValue)
      Retrieve the argument, if any, of an option.
      Parameters:
      name - character name of the option
      defaultValue - the default value to be returned if the option is not specified
      Returns:
      the value of the argument if option is set, and has an argument, otherwise defaultValue
    • resolveOption

      public Option resolveOption(String name)
      Retrieves the option object given the long or short option as a String.
      Parameters:
      name - the short or long name of the option
      Returns:
      the canonicalized option
    • getProperties

      public Properties getProperties(Option option)
      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:
      option - the option to be processed
      Returns:
      the Properties mapped by the option, never null even if the option doesn't exists
    • getProperties

      public Properties getProperties(String name)
      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:
      name - the name of the option
      Returns:
      the Properties mapped by the option, never null even if the option doesn't exists
    • addOption

      protected void addOption(Option opt)
      Add an option. The values of the option are stored.
      Parameters:
      opt - the option to be processed
    • iterator

      public Iterator<Option> iterator()
      Returns an iterator over the Option members of ParsedOptions.
      Returns:
      an Iterator over the processed Option members of this ParsedOptions
    • getOptions

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

      public boolean hasArgs()
      Checks if non-recognized options or arguments exists.
      Returns:
      true if non-recognized options or arguments exists; false otherwise
    • getArgs

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

      public String getFirstArg()
    • getArgList

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

      protected void addArg(String arg)
      Add left-over unrecognized option/argument.
      Parameters:
      arg - the unrecognized option/argument