|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.foxsmart.ic.util.CommandLineParams
public class CommandLineParams
This class provides the ability to define and parse command line parameters to a Java main program.
A command line takes the form of the program name along with any number of flags (e.g. -a) along with any number of options (e.g. -p ) along with any number of arguments (e.g. ). "Flags" are always optional. "Options" are optional or required. "Arguments" are always required.
| Constructor Summary | |
|---|---|
CommandLineParams()
Construct a new CommandLineArgs object. |
|
| Method Summary | |
|---|---|
void |
addArgument(java.lang.String name,
java.lang.String description)
Adds a command line argument. |
void |
addFlag(java.lang.String flag,
java.lang.String name,
java.lang.String description)
Adds a command line flag. |
void |
addOption(java.lang.String option,
java.lang.String name,
java.lang.String description,
boolean required)
Adds a command line option. |
boolean |
containsFlag(java.lang.String flag)
Returns whether the command line parameters contained the specified flag. |
boolean |
containsOption(java.lang.String option)
Returns whether the command line parameters contained the specified option. |
java.lang.String |
getAdditionUsage()
Gets the additional usage text if specified. |
java.lang.String |
getArgument(java.lang.String name)
Gets the value of the specified argument. |
java.lang.String |
getOption(java.lang.String option)
Gets the value of the specified option. |
java.lang.String |
getProgramName()
Gets the program name. |
java.lang.String |
getUsage()
Gets the usage description for the program. |
void |
parse(java.lang.String[] args)
Parses command line arguments and compares the arguments to what is expected. |
void |
removeArgument(java.lang.String name)
Removes a command line argument. |
void |
removeFlag(java.lang.String flag)
Removes a command line flag. |
void |
removeOption(java.lang.String option)
Removes a command line option. |
void |
reset()
Resets the previously parsed parameters. |
void |
setAdditionalUsage(java.lang.String additionalUsage)
Sets any additional usage text that will be appended to the end of the usage statement. |
void |
setProgramName(java.lang.String programName)
Sets the program name. |
void |
setUsage(java.lang.String usage)
Sets the usage statement. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandLineParams()
| Method Detail |
|---|
public void reset()
public void addFlag(java.lang.String flag,
java.lang.String name,
java.lang.String description)
flag - A command line flag. The "-" prefix is not required.name - The name of the flag.description - A description of the flag. Used for building a usage statement.public void removeFlag(java.lang.String flag)
flag - A command line flag. The "-" prefix is not required.public boolean containsFlag(java.lang.String flag)
flag - A command line flag. The "-" prefix is not required.
public void addOption(java.lang.String option,
java.lang.String name,
java.lang.String description,
boolean required)
option - A command line option. The "-" prefix is not required.name - The name of the option.description - A description of the option. Used for building a usage statement.required - True if the option is required or false if the option is optional.public void removeOption(java.lang.String option)
option - A command line option. The "-" prefix is not required.public boolean containsOption(java.lang.String option)
option - A command line option. The "-" prefix is not required.
public java.lang.String getOption(java.lang.String option)
option - A command line option. The "-" prefix is not required.
public void addArgument(java.lang.String name,
java.lang.String description)
name - A command line argument. Arguments can not start with the "-" prefix. If a prefix is found, it will
be removed.description - A description of the argument. Used for building a usage statement.public void removeArgument(java.lang.String name)
name - A command line argument. Arguments can not start with the "-" prefix. If a prefix is found, it will
be removed.public java.lang.String getArgument(java.lang.String name)
name - A command line argument. Arguments can not start with the "-" prefix. If a prefix is found, it will
be removed.
public void setProgramName(java.lang.String programName)
programName - The name of the program.public void setUsage(java.lang.String usage)
usage - A description of the program usage.public void setAdditionalUsage(java.lang.String additionalUsage)
additionalUsage - Additional Usage text.public java.lang.String getProgramName()
public java.lang.String getUsage()
public java.lang.String getAdditionUsage()
public void parse(java.lang.String[] args)
throws java.lang.Exception
args - program arguments.
java.lang.Exception - if the arguments specified do not match what is expected.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||