Creates a command line options parser from a command line specification. This is passed to this constructor
as an array of arrays of strings. Each array of strings specifies the command line for a single option. A static
array may therefore easily be used to configure the command line parser in a single method call with an easily
readable format.
Each array of strings must be 2, 3, 4 or 5 elements long. If any of the last three elements are missing they
are assumed to be null. The elements specify the following parameters:
- The name of the option without the leading '-'. For example, "file". To specify the format of the 'free'
arguments use the option names "1", "2", ... and so on.
- The option comment. A line of text describing the usage of the option. For example, "The file to be processed."
- The options argument. This is a very short description of the argument to the option, often a single word
or a reminder as to the arguments format. When this element is null the option is a flag and does not
accept any arguments. For example, "filename" or "(unix | windows)" or null. The actual text specified
is only used to print in the usage message to remind the user of the usage of the option.
- The mandatory flag. When set to "true" an option must always be specified. Any other value, including null,
means that the option is mandatory. Flags are always mandatory (see class javadoc for explanation of why) so
this is ignored for flags.
- A regular expression describing the format that the argument must take. Ignored if null.
An example call to this constructor is:
CommandLineParser commandLine = new CommandLineParser(
new String[][] {{"file", "The file to be processed. ", "filename", "true"},
{"dir", "Directory to store results in. Current dir used if not set.", "out dir"},
{"os", "Operating system EOL format to use.", "(windows | unix)", null, "windows\|unix"},
{"v", "Verbose mode. Prints information about the processing as it goes."},
{"1", "The processing command to run.", "command", "true", "add\|remove\|list"}});