|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jcon.util.CommandLineSyntax
public class CommandLineSyntax
Describes the syntax for a command-line tool.
Supports the definition of a command-line syntax much like that provided by the GNU command-line utilities found through the UNIX/Linux world.
Interprets these for your program, substituting defaults and such, and spares the annoyance of doing lots of processing in your main() to figure out what the user wants.
| Constructor Summary | |
|---|---|
CommandLineSyntax()
|
|
CommandLineSyntax(java.util.ArrayList arguments,
java.util.ArrayList options)
|
|
| Method Summary | |
|---|---|
java.lang.String |
buildHelpMessage()
Builds a help message describing the syntax. |
void |
die(java.lang.String reason)
Exits with a handy information message. |
java.util.ArrayList |
getArguments()
|
PropMap |
getDefaultProperties()
|
CommandLineOption |
getOptionFor(java.lang.String flag)
Looks up the option specified by the given String (which has a "-" or "--" prefix) |
java.util.ArrayList |
getOptions()
|
java.lang.String |
getSynopsis()
|
java.lang.String |
getVarargsName()
If a list of args appears at the end of the syntax, this is the name that describes it. |
PropMap |
parse(java.lang.String[] commandLine)
This is where it all happens. |
PropMap |
parseOrDie(java.lang.String[] commandLine)
Alternately, this is where it all happens. |
void |
setArguments(java.util.ArrayList newArguments)
|
void |
setOptions(java.util.ArrayList newOptions)
|
void |
setSynopsis(java.lang.String newSynopsis)
|
void |
setVarargsName(java.lang.String newVarargsName)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandLineSyntax()
public CommandLineSyntax(java.util.ArrayList arguments,
java.util.ArrayList options)
| Method Detail |
|---|
public PropMap parse(java.lang.String[] commandLine)
throws CommandLineParseException
Parses a command line argument array using the syntax; returns a Map keyed by option or argument name containing the value (boolean for switches, String for others) obtained or defaulted for each.
CommandLineParseExceptionpublic PropMap parseOrDie(java.lang.String[] commandLine)
This is a convenience method that takes care of the quite common case where you want to simply exit if the command line is unparseable; printing out a nice help message so the user knows better next time.
Also, if you have defined a -h, --help option, it will print the nice help message as well.
Variable-length args (e.g. a list of things at the end of the command) are provided in a property called "remainingArgs".
public void die(java.lang.String reason)
public CommandLineOption getOptionFor(java.lang.String flag)
public java.lang.String buildHelpMessage()
public java.util.ArrayList getArguments()
public void setArguments(java.util.ArrayList newArguments)
public java.util.ArrayList getOptions()
public void setOptions(java.util.ArrayList newOptions)
public java.lang.String getSynopsis()
public void setSynopsis(java.lang.String newSynopsis)
public java.lang.String getVarargsName()
public void setVarargsName(java.lang.String newVarargsName)
public PropMap getDefaultProperties()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||