All Packages Class Hierarchy This Package Previous Next Index
Class ncsa.MBone.Utils.CommandLineParser
java.lang.Object
|
+----ncsa.MBone.Utils.CommandLineParser
- public class CommandLineParser
- extends Object
Parse a command line, returning options, and option arguments.
-
CommandLineParser(String)
- Initialize the parser with default values.
-
CommandLineParser(String, String)
- Initialize the parser with default values.
-
CommandLineParser(String, String, String, String)
- Initialize the parser.
-
CommandLineParser(String[])
- Initialize the parser with default values taken from an array.
-
countOptionArgs(String)
- Returns the number of args related to an option.
-
countOptions()
- Returns the number of options parsed.
-
getArgsWithoutOption()
-
-
getOptionArgs(String)
- Returns an array filled with the arguments related to an option.
-
getOptionArgsLine(String)
- Returns a single string with all the option related arguments.
-
getOptions()
- Returns a string table with the option names.
-
isOption(String)
- Returns true if the speficied option is on the command_line.
-
main(String[])
- Intended to test the class
Seems to work.
-
parse()
- Parses a string with respect to previously registered options.
-
registerOption(String)
- Adds an option to be parsed.
-
registerOption(String, int)
- Adds an option to be parsed.
-
registerOptions(String[], int[])
- Adds options to be parsed.
CommandLineParser
public CommandLineParser(String command_line)
- Initialize the parser with default values.
The option mark is "-", the option-arg separator is " "
the arguments delimiter is " ".
- Parameters:
- command_line - The command line to be parsed.
CommandLineParser
public CommandLineParser(String line[])
- Initialize the parser with default values taken from an array.
It is assumed that the option end mark is the same as the delimiter
CommandLineParser
public CommandLineParser(String command_line,
String option_mark)
- Initialize the parser with default values.
The option-arg separator is " ",
the arguments delimiter is " ".
- Parameters:
- command_line - The command line to be parsed.
- option_mark - The string preceding an option.
CommandLineParser
public CommandLineParser(String command_line,
String option_mark,
String option_arg_separator,
String arg_delimiter)
- Initialize the parser.
- Parameters:
- command_line - The command line to be parsed.
- option_mark - The string preceding an option.
- option_arg_separator - The string between option names and
their first argument, if any.
- arg_delimiter - The string separating option arguments.
registerOption
public void registerOption(String name,
int number_args)
- Adds an option to be parsed.
- Parameters:
- name - The option name.
- number_args - The option number of arguments, if fixed.
May be zero. If negative, the number is considered variable.
registerOption
public void registerOption(String name)
- Adds an option to be parsed.
- Parameters:
- name - The option name.
It is assumed thereby that this option takes a variable number
arguments. The arguments which will be considered related to
this option will be those between the present option and the
next one, if any. If none, all following arguments are considered
related to the option.
registerOptions
public void registerOptions(String names[],
int number_args[])
- Adds options to be parsed.
- Parameters:
- names - The option names array.
- number_args - The number of arguments array. If any number
is found to be strictly negative, it is assumed that the number
or arguments is variable. See registerOption (String name) for
further details on option arguments in this case.
parse
public void parse() throws NotEnoughArgsException
- Parses a string with respect to previously registered options.
getOptions
public String[] getOptions()
- Returns a string table with the option names.
returns null if there is no option registered.
getOptionArgs
public String[] getOptionArgs(String name) throws NoSuchOptionException
- Returns an array filled with the arguments related to an option.
If there is a fixed non zero, or variable option number 'n' of
arguments, the immediately 'n' following parsed arguments are returned.
If there is no arguments for the option, null is returned.
- Parameters:
- name - The option name.
- Throws: NoSuchOptionException
- if the option has not been registered.
getOptionArgsLine
public String getOptionArgsLine(String name) throws NoSuchOptionException
- Returns a single string with all the option related arguments.
See getOptionArgs() for further details upon related arguments.
The string is trimmed with respect to the delimiter specified.
That is between two arguments there is exactly one delimiter,
and none before the first argument, or after the last one.
- Parameters:
- name - The option name.
Trimming still unimplemented.
getArgsWithoutOption
public String[] getArgsWithoutOption()
isOption
public boolean isOption(String name) throws NoSuchOptionException
- Returns true if the speficied option is on the command_line.
Returns false in other cases.
- Parameters:
- name - The option name.
- Throws: NoSuchOptionException
- if the option has not been registered.
countOptions
public int countOptions()
- Returns the number of options parsed.
countOptionArgs
public int countOptionArgs(String name) throws NoSuchOptionException
- Returns the number of args related to an option.
This may be different for the number of args expected.
- Parameters:
- name - The option name.
- Throws: NoSuchOptionException
- if the option has not been registered.
main
public static void main(String args[]) throws ParserException
- Intended to test the class
Seems to work. Check coherence when no arg for an option.
No orphan arg feature for now.
All Packages Class Hierarchy This Package Previous Next Index