public final class CommandLineUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static ParsedCommandLine |
parse(java.lang.String[] argv,
java.lang.String switchPrefix,
java.lang.String[] validSwitches,
java.lang.String[] requiredSwitches,
java.lang.String[] argSwitches)
"Parses" a command line by making use several conventions:
Certain arguments are considered "switches", by virtue
of being prefixed with some string, usually "-", "/", or "--"
Switches may have arguments associated with them.
|
public static ParsedCommandLine parse(java.lang.String[] argv, java.lang.String switchPrefix, java.lang.String[] validSwitches, java.lang.String[] requiredSwitches, java.lang.String[] argSwitches) throws BadCommandLineException
argv
- the entire list of arguments, usually the argument to a main functionswitchPrefix
- the string which separates "switches" from regular command line args.
Must be non-nullvalidSwitches
- a list of all the switches permissible for this command line.
If non-null, an UnexpectedSwitchException will be thrown if a switch not
in this list is encountered. Use null to accept any switches.requiredSwitches
- a list of all the switches required by this command line.
If non-null, an MissingSwitchException will be thrown if a switch
in this list is not present. Use null if no switches should be considered required.argSwitches
- a list of switches that should have an argument associated with them
If non-null, an MissingSwitchArgumentException will be thrown if a switch
in this list has no argument is not present. Use null if no switches should
be considered to require arguments. However, this parameter is required if
distinct items on a command line should be considered arguments to preceding
items. (For example, "f" must be an argSwitch for "-f myfile.txt" to be parsed
as switch and argument, but argSwitches is not required to parse "--file=myfile.txt"BadCommandLineException