ariba.util.core
Class ArgumentParser

java.lang.Object
  extended by ariba.util.core.ArgumentParser

public class ArgumentParser
extends java.lang.Object

Provide a cleaner way of handling arguments to public static void main (String args[]).


Field Summary
static java.lang.String BooleanDefault
           
static java.lang.String[] globalArgs
          Cache of VM command line arguments aribaapi ariba because the util unit test uses it.
static boolean globalIgnoreCase
          Indicates if we should ignore the case of the comand line arguments aribaapi ariba because unit test uses it.
static boolean IgnoreCaseDefault
           
static java.lang.String NoPrefix
           
static java.lang.Object Null
          Constant for lame Map and vector classes.
static java.lang.String OptionalClose
           
static java.lang.String OptionalOpen
           
static java.lang.String RequiredClose
           
static java.lang.String RequiredOpen
           
static java.lang.String SwitchPrefix
           
static int TypeBoolean
           
static int TypeDouble
           
static int TypeFile
           
static int TypeInteger
           
static int TypeIntegerList
           
static int TypeString
           
static int TypeURL
           
static java.lang.String ValidChoices
           
 
Constructor Summary
ArgumentParser(java.lang.String usage, java.lang.String[] args)
          Constructor takes the args to parse and user supplied usage string
ArgumentParser(java.lang.String usage, java.lang.String[] args, boolean ignoreCase)
          Constructor takes the args to parse and user supplied usage string
ArgumentParser(java.lang.String usage, java.lang.String[] args, boolean ignoreCase, boolean exitUponParsingError)
          Constructor takes the args to parse and user supplied usage string
 
Method Summary
 void addOptionalBoolean(java.lang.String name, boolean defaultValue)
          Add an optional boolean argument
 void addOptionalBoolean(java.lang.String name, boolean defaultValue, java.lang.String usage)
          Add an optional boolean argument
 void addOptionalDouble(java.lang.String name, double defaultValue, java.lang.String usage)
          Add an optional double argument
 void addOptionalFile(java.lang.String name, java.io.File defaultValue, java.lang.String usage)
          Add an optional file argument
 void addOptionalInteger(java.lang.String name, int defaultValue, java.lang.String usage)
          Add an optional integer argument
 void addOptionalIntegerList(java.lang.String name, java.util.List defaultValue, java.lang.String usage)
          Add an optional integer range argument
 void addOptionalString(java.lang.String name, java.lang.String defaultValue, java.lang.String usage)
          Add an optional string argument
 void addOptionalURL(java.lang.String name, java.net.URL defaultValue, java.lang.String usage)
          Add an optional url argument
 void addRequiredBoolean(java.lang.String name)
          Add a required boolean argument
 void addRequiredBoolean(java.lang.String name, java.lang.String usage)
          Add a required boolean argument
 void addRequiredDouble(java.lang.String name, java.lang.String usage)
          Add a required double argument
 void addRequiredFile(java.lang.String name, java.lang.String usage)
          Add a required file argument
 void addRequiredInteger(java.lang.String name, java.lang.String usage)
          Add a required integer argument
 void addRequiredIntegerList(java.lang.String name, java.lang.String usage)
          Add a required integer range argument
 void addRequiredString(java.lang.String name, java.lang.String usage)
          Add a required string argument
 void addRequiredURL(java.lang.String name, java.lang.String usage)
          Add a required url argument
 java.lang.String[] args()
          Return the arguments for purposes such as printing
static void create(java.lang.String className, java.lang.String[] args)
          Create an instance of the command line client.
static void create(java.lang.String className, java.lang.String[] args, boolean ignoreCase)
          Convenience method for creating a command line client without the optional context.
static void create(java.lang.String className, java.lang.String[] args, boolean ignoreCase, java.lang.Object context)
          Create a command line client.
static void create(java.lang.String className, java.lang.String[] args, java.lang.Object context)
           
 boolean getBoolean(java.lang.String name)
          retrieve the value of a boolean argument
 double getDouble(java.lang.String name)
          retrieve the value of a double argument
 java.io.File getFile(java.lang.String name)
          retrieve the value of a file argument
static java.lang.String getHackedParameter(java.lang.String name)
          This is needed to get the nodename from the command line before the log is created and before most of the rest of the setup is done.
 int getInteger(java.lang.String name)
          retrieve the value of a integer argument
 java.util.List getIntegerList(java.lang.String name)
          retrieve the value of a integer range argument
 java.util.List getListOf(java.lang.String name)
          Returns a vector of values for the argument name specified.
 java.lang.String getString(java.lang.String name)
          retrieve the value of a string argument
 java.net.URL getURL(java.lang.String name)
          retrieve the value of a url argument
 java.lang.String image()
          Print the argument list
static java.lang.String negate(java.lang.String name)
          given foo returns noFoo
static CommandLine newInstance(java.lang.String className, java.lang.String[] args)
          The first part of create: creates a new instance of the specified comand line client class.
static CommandLine newInstance(java.lang.String className, java.lang.String[] args, boolean ignoreCase)
          The first part of create: creates a new instance of the specified comand line client class.
static void startup(CommandLine client)
          The second part of create, starting an existing instance.
 void usage()
          Print a usage statement and exit
 void usage(java.lang.String error)
          Print a usage statement and exit
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalArgs

public static java.lang.String[] globalArgs
Cache of VM command line arguments aribaapi ariba because the util unit test uses it.


IgnoreCaseDefault

public static boolean IgnoreCaseDefault

globalIgnoreCase

public static boolean globalIgnoreCase
Indicates if we should ignore the case of the comand line arguments aribaapi ariba because unit test uses it.


TypeString

public static final int TypeString
See Also:
Constant Field Values

TypeBoolean

public static final int TypeBoolean
See Also:
Constant Field Values

TypeInteger

public static final int TypeInteger
See Also:
Constant Field Values

TypeDouble

public static final int TypeDouble
See Also:
Constant Field Values

TypeFile

public static final int TypeFile
See Also:
Constant Field Values

TypeURL

public static final int TypeURL
See Also:
Constant Field Values

TypeIntegerList

public static final int TypeIntegerList
See Also:
Constant Field Values

RequiredOpen

public static final java.lang.String RequiredOpen
See Also:
Constant Field Values

RequiredClose

public static final java.lang.String RequiredClose
See Also:
Constant Field Values

OptionalOpen

public static final java.lang.String OptionalOpen
See Also:
Constant Field Values

OptionalClose

public static final java.lang.String OptionalClose
See Also:
Constant Field Values

BooleanDefault

public static final java.lang.String BooleanDefault
See Also:
Constant Field Values

ValidChoices

public static final java.lang.String ValidChoices
See Also:
Constant Field Values

SwitchPrefix

public static final java.lang.String SwitchPrefix
See Also:
Constant Field Values

NoPrefix

public static final java.lang.String NoPrefix
See Also:
Constant Field Values

Null

public static final java.lang.Object Null
Constant for lame Map and vector classes.

Constructor Detail

ArgumentParser

public ArgumentParser(java.lang.String usage,
                      java.lang.String[] args)
Constructor takes the args to parse and user supplied usage string

Parameters:
usage - specifies command line option usage
args - the command line arguments

ArgumentParser

public ArgumentParser(java.lang.String usage,
                      java.lang.String[] args,
                      boolean ignoreCase)
Constructor takes the args to parse and user supplied usage string

Parameters:
usage - specifies command line option usage
args - the command line arguments
ignoreCase - when true flags of differing case compare equal

ArgumentParser

public ArgumentParser(java.lang.String usage,
                      java.lang.String[] args,
                      boolean ignoreCase,
                      boolean exitUponParsingError)
Constructor takes the args to parse and user supplied usage string

Parameters:
usage - specifies command line option usage
args - the command line arguments
ignoreCase - when true flags of differing case compare equal
exitUponParsingError - when false parsing error will be reported by an IllegalArgumentException while when true the VM will exit
Method Detail

create

public static void create(java.lang.String className,
                          java.lang.String[] args)
Create an instance of the command line client. Then invokes the command line client's methods in the following order: (1) setupArgument to let the client set up its commmand line arguments; (2) processArguments to let the client process and parse its arguments; (3) startup to run the client.

Parameters:
className - the command line client class
args - the command line arguments of the class, must be non null
See Also:
CommandLine

newInstance

public static CommandLine newInstance(java.lang.String className,
                                      java.lang.String[] args)
The first part of create: creates a new instance of the specified comand line client class. Sometimes we need to create it without starting it right away.

Parameters:
className - the class name of the command line client
args - its associated command line arguments, must be non-null.

create

public static void create(java.lang.String className,
                          java.lang.String[] args,
                          boolean ignoreCase,
                          java.lang.Object context)
Create a command line client. Then invokes the command line client's methods in the following order: (1) setupArgument to let the client set up its commmand line arguments; (2) processArguments to let the client process and parse its arguments; (3) startup to run the client.

Parameters:
className - the command line client class
args - the command line arguments of the class. Must be non null.
ignoreCase - when true flags of differing case compare equal
context - information to be passed to the command, in addition to the args.
See Also:
CommandLine

create

public static void create(java.lang.String className,
                          java.lang.String[] args,
                          boolean ignoreCase)
Convenience method for creating a command line client without the optional context.

Parameters:
className - the command line client class
args - the command line arguments of the class. Must be non null.
ignoreCase - when true flags of differing case compare equal.

create

public static void create(java.lang.String className,
                          java.lang.String[] args,
                          java.lang.Object context)

newInstance

public static CommandLine newInstance(java.lang.String className,
                                      java.lang.String[] args,
                                      boolean ignoreCase)
The first part of create: creates a new instance of the specified comand line client class. Sometimes we need to create it without starting it right away.

Parameters:
className - the class name of the command line client
args - its associated command line arguments, must be non-null.
ignoreCase - when true flags of differing case compare equal

startup

public static void startup(CommandLine client)
The second part of create, starting an existing instance. Sometimes we need to start a precreated CommandLine.

Parameters:
client - the command line client to start executing. must be non null. aribaapi ariba because unit test uses it.

args

public java.lang.String[] args()
Return the arguments for purposes such as printing

Returns:
the command line arguments

addRequiredString

public void addRequiredString(java.lang.String name,
                              java.lang.String usage)
Add a required string argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalString

public void addOptionalString(java.lang.String name,
                              java.lang.String defaultValue,
                              java.lang.String usage)
Add an optional string argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

addRequiredInteger

public void addRequiredInteger(java.lang.String name,
                               java.lang.String usage)
Add a required integer argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalInteger

public void addOptionalInteger(java.lang.String name,
                               int defaultValue,
                               java.lang.String usage)
Add an optional integer argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

addRequiredDouble

public void addRequiredDouble(java.lang.String name,
                              java.lang.String usage)
Add a required double argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalDouble

public void addOptionalDouble(java.lang.String name,
                              double defaultValue,
                              java.lang.String usage)
Add an optional double argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

addRequiredBoolean

public void addRequiredBoolean(java.lang.String name)
Add a required boolean argument

Parameters:
name - name of the command line option

addRequiredBoolean

public void addRequiredBoolean(java.lang.String name,
                               java.lang.String usage)
Add a required boolean argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalBoolean

public void addOptionalBoolean(java.lang.String name,
                               boolean defaultValue)
Add an optional boolean argument

Parameters:
name - name of the command line option
defaultValue - the default value to use if the option does not appear in the command line

addOptionalBoolean

public void addOptionalBoolean(java.lang.String name,
                               boolean defaultValue,
                               java.lang.String usage)
Add an optional boolean argument

Parameters:
name - name of the command line option
usage - usage of this argument, if null, the usage will not be displayed.
defaultValue - the default value to use if the option does not appear in the command line

addRequiredFile

public void addRequiredFile(java.lang.String name,
                            java.lang.String usage)
Add a required file argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalFile

public void addOptionalFile(java.lang.String name,
                            java.io.File defaultValue,
                            java.lang.String usage)
Add an optional file argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

addRequiredURL

public void addRequiredURL(java.lang.String name,
                           java.lang.String usage)
Add a required url argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalURL

public void addOptionalURL(java.lang.String name,
                           java.net.URL defaultValue,
                           java.lang.String usage)
Add an optional url argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

addRequiredIntegerList

public void addRequiredIntegerList(java.lang.String name,
                                   java.lang.String usage)
Add a required integer range argument

Parameters:
name - name of the command line option
usage - usage of this argument

addOptionalIntegerList

public void addOptionalIntegerList(java.lang.String name,
                                   java.util.List defaultValue,
                                   java.lang.String usage)
Add an optional integer range argument

Parameters:
name - name of the command line option
usage - usage of this argument
defaultValue - the default value to use if the option does not appear in the command line

getListOf

public java.util.List getListOf(java.lang.String name)
Returns a vector of values for the argument name specified. If none have been set, a null vector will be returned.

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the vector of values as specified above.

getString

public java.lang.String getString(java.lang.String name)
retrieve the value of a string argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of a string argument

getBoolean

public boolean getBoolean(java.lang.String name)
retrieve the value of a boolean argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value fo the boolean argument

getInteger

public int getInteger(java.lang.String name)
retrieve the value of a integer argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of the integer argument

getDouble

public double getDouble(java.lang.String name)
retrieve the value of a double argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of a double argument

getFile

public java.io.File getFile(java.lang.String name)
retrieve the value of a file argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of a file argument

getURL

public java.net.URL getURL(java.lang.String name)
retrieve the value of a url argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of a url argument

getIntegerList

public java.util.List getIntegerList(java.lang.String name)
retrieve the value of a integer range argument

Parameters:
name - the name of the parameter whose value is to be returned
Returns:
the value of the integer range argument

usage

public void usage(java.lang.String error)
Print a usage statement and exit

Parameters:
error - the usage string

usage

public void usage()
Print a usage statement and exit


image

public java.lang.String image()
Print the argument list


negate

public static java.lang.String negate(java.lang.String name)
given foo returns noFoo

Parameters:
name - String to negate
Returns:
the negated string

getHackedParameter

public static java.lang.String getHackedParameter(java.lang.String name)
This is needed to get the nodename from the command line before the log is created and before most of the rest of the setup is done. DO not use it without talking to the core server group!

Parameters:
name - the name of the parameter
Returns:
the value of the parameter.


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.