|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.CommandLineParser
public class CommandLineParser
A class to parse command line arguments. All command line switches identified are stored in the appropriate fields, regardless of their appearance within the command line. Command line arguments that can not be identified as command line switches or their arguments are stored in their order of appearance in a separate list. Note that prior to parsing a list of command line switches must be registered.
| Nested Class Summary | |
|---|---|
static class |
CommandLineParser.Test
Test purpose only. |
| Field Summary | |
|---|---|
private List<String> |
argument
The list of unmatched command line arguments. |
private Map<Integer,Set<String>> |
countToSwitch
A table linking command line switches to their element numbers. |
private String |
line
The concated command line arguments, available after parsing. |
private Map<String,List<String>> |
switchFound
The table of found command line switches. |
| Constructor Summary | |
|---|---|
CommandLineParser()
Constructs a new command line argument parser. |
|
| Method Summary | |
|---|---|
List<String> |
getArguments(String toswitch)
Returns the arguments associated with the given command line switch. |
protected String |
getCommandLine()
Returns the original command line. |
List<String> |
getCommands()
Returns the true arguements of the command lines. |
protected Set<String> |
getRegisteredSwitches(int num)
Returns all registered switches to the given argument count. |
boolean |
hasAnySwitch(List<String> all)
Checks, if we have any of these switches. |
boolean |
hasSwitch()
Returns true if at least one of the command line switches has been found. |
boolean |
hasSwitch(String switchname)
Returns true if at least one of the command line switches has been found. |
boolean |
haveAllSwitches(List<String> all)
Checks, if we have all switches. |
void |
parse(String[] commandline)
Parses the command line arguments. |
void |
printCommandLine(PrintStream out,
String[] arg)
Prints the command line as a hashed string to the specified stream. |
void |
registerLine(String line,
int count)
Convenience method to add command line switches gather together on a single string. |
void |
registerSwitches(Set<String> switches,
int count)
Register a set of command line switches to this parser. |
void |
setCommands(List<String> set)
Sets the non-switches of the command lines, i.e. |
static void |
staticUsage(Class parser,
Map<Integer,Set<String>> switches,
Map<String,String> detail,
String footer)
For classes that don't want to instantiate a command line parser, but still want to print the standardized usage. |
void |
usage(Map<String,String> detail,
String footer)
Dumps a usage message to System.out. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Map<Integer,Set<String>> countToSwitch
private Map<String,List<String>> switchFound
private List<String> argument
private String line
| Constructor Detail |
|---|
public CommandLineParser()
| Method Detail |
|---|
public void registerLine(String line,
int count)
public void registerSwitches(Set<String> switches,
int count)
public void parse(String[] commandline)
throws ParseException
ParseException
public void printCommandLine(PrintStream out,
String[] arg)
public List<String> getArguments(String toswitch)
public boolean hasSwitch()
public boolean hasSwitch(String switchname)
public boolean haveAllSwitches(List<String> all)
public boolean hasAnySwitch(List<String> all)
public List<String> getCommands()
public void setCommands(List<String> set)
public void usage(Map<String,String> detail,
String footer)
public static void staticUsage(Class parser,
Map<Integer,Set<String>> switches,
Map<String,String> detail,
String footer)
parser - The class to print the usage for.switches - A mapping of argument numbers to sets of switches.detail - Details of usage of switchesfooter - What the commands mean.protected Set<String> getRegisteredSwitches(int num)
protected String getCommandLine()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||