org.osesb.utilities.language
Class CommandLineOptions

java.lang.Object
  extended by org.osesb.utilities.language.CommandLineOptions

public class CommandLineOptions
extends java.lang.Object

Class that parses command line arguments using jakarta-commons-cli. The class provides two constructors. The first will parse command line arguments against pre-registered command line options that are used throughout the framework (see the static initialization). The second, does the same, but allows the caller to pass additional Options to parse against.

Since:
Version .9

Field Summary
protected  org.apache.commons.cli.Options allOptions
          all options - registered and added.
protected  org.apache.commons.cli.CommandLine commandLine
          CommandLine object.
protected  java.lang.String[] commandlineArgs
          the arguments we were created with.
protected static org.apache.commons.cli.Options registeredOptions
          Registered options - the options we know about.
 
Constructor Summary
CommandLineOptions(java.lang.String[] args)
          Creates a new instance of CommandLineOptions using the pre-registered options, above.
CommandLineOptions(java.lang.String[] args, org.apache.commons.cli.Options additionalOptions)
          Creates a new instance of CommandLineOptions using the pre-registered options, above, and additional Options passed by the caller.
 
Method Summary
 void addOption(org.apache.commons.cli.Option option)
          Add an option to registeredOptions.
 org.apache.commons.cli.CommandLine getCommandLine()
          Returns an org.apache.commons.cli.CommandLine Object that results from parsing the command line against the registered Options.
 java.lang.String getOptionValue(java.lang.String option)
          Returns the value of a command line argument.
 java.lang.String getOptionValue(java.lang.String option, java.lang.String defaultValue)
          Returns the value of a command line argument.
 boolean hasOption(java.lang.String option)
          Returns true if the command line contains the option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandLine

protected org.apache.commons.cli.CommandLine commandLine
CommandLine object.


registeredOptions

protected static org.apache.commons.cli.Options registeredOptions
Registered options - the options we know about.


allOptions

protected org.apache.commons.cli.Options allOptions
all options - registered and added.


commandlineArgs

protected java.lang.String[] commandlineArgs
the arguments we were created with.

Constructor Detail

CommandLineOptions

public CommandLineOptions(java.lang.String[] args)
                   throws java.lang.Exception
Creates a new instance of CommandLineOptions using the pre-registered options, above.

Parameters:
args - The commandline arguments to parse.
Throws:
java.lang.Exception - if there are problems parsing the command line arguments. The caller will normally display a usage summary on an exception.

CommandLineOptions

public CommandLineOptions(java.lang.String[] args,
                          org.apache.commons.cli.Options additionalOptions)
                   throws java.lang.Exception
Creates a new instance of CommandLineOptions using the pre-registered options, above, and additional Options passed by the caller.

Parameters:
args - The commandline arguments to parse.
additionalOptions - Additional org.apache.commons.cli.Options to use when parsing the command line.
Throws:
java.lang.Exception - if there are problems parsing the command line arguments. The caller will normally display a usage summary on an exception.
Method Detail

addOption

public void addOption(org.apache.commons.cli.Option option)
               throws java.lang.Exception
Add an option to registeredOptions.

Parameters:
option - The Option to add.
Throws:
java.lang.Exception - if there are problems parsing the command line arguments against the options.

getOptionValue

public java.lang.String getOptionValue(java.lang.String option)
Returns the value of a command line argument.

Parameters:
option - The command line argument to get the value of.
Returns:
the option's value.

getOptionValue

public java.lang.String getOptionValue(java.lang.String option,
                                       java.lang.String defaultValue)
Returns the value of a command line argument.

Parameters:
option - The command line argument to get the value of.
defaultValue - The value to be returned if the command line argument was not found.
Returns:
the option's value or it's defau;t value.

hasOption

public boolean hasOption(java.lang.String option)
Returns true if the command line contains the option.

Parameters:
option - The command line argument to check.
Returns:
true of the command line contains the option.

getCommandLine

public org.apache.commons.cli.CommandLine getCommandLine()
Returns an org.apache.commons.cli.CommandLine Object that results from parsing the command line against the registered Options.

Returns:
option The CommandLine object for the parsed command line.