Top Constructors Methods
com.mchange.v2.cmdline

public final Class CommandLineUtils

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ParsedCommandLine
parse(String[]
the entire list of arguments, usually the argument to a main function
argv
,
String
the string which separates "switches" from regular command line args. Must be non-null
switchPrefix
,
String[]
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.
validSwitches
,
String[]
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.
requiredSwitches
,
String[]
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"
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. This implementation permits only a single argument per switch
  • Switch arguments are determined via two conventions:
    1. If a switch is of the form "--switch=value" (where "--" is set as the switch prefix), value is the switches argument.
    2. If a switch is not of this form (simply "--switch"), then the following item on the command line is considered the switch's argument if and only if
      1. the argSwitches array contains the switch, and
      2. the next item on the command line is not itself a switch
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CommandLineUtilsback to summary
private CommandLineUtils()

Method Detail

parseback to summary
public static ParsedCommandLine parse(String[] argv, String switchPrefix, String[] validSwitches, String[] requiredSwitches, String[] argSwitches) throws BadCommandLineException

"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. This implementation permits only a single argument per switch
  • Switch arguments are determined via two conventions:
    1. If a switch is of the form "--switch=value" (where "--" is set as the switch prefix), value is the switches argument.
    2. If a switch is not of this form (simply "--switch"), then the following item on the command line is considered the switch's argument if and only if
      1. the argSwitches array contains the switch, and
      2. the next item on the command line is not itself a switch
Parameters
argv:String[]

the entire list of arguments, usually the argument to a main function

switchPrefix:String

the string which separates "switches" from regular command line args. Must be non-null

validSwitches:String[]

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:String[]

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:String[]

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"