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.


Constructor Index

 o CommandLineParser(String)
Initialize the parser with default values.
 o CommandLineParser(String, String)
Initialize the parser with default values.
 o CommandLineParser(String, String, String, String)
Initialize the parser.
 o CommandLineParser(String[])
Initialize the parser with default values taken from an array.

Method Index

 o countOptionArgs(String)
Returns the number of args related to an option.
 o countOptions()
Returns the number of options parsed.
 o getArgsWithoutOption()
 o getOptionArgs(String)
Returns an array filled with the arguments related to an option.
 o getOptionArgsLine(String)
Returns a single string with all the option related arguments.
 o getOptions()
Returns a string table with the option names.
 o isOption(String)
Returns true if the speficied option is on the command_line.
 o main(String[])
Intended to test the class Seems to work.
 o parse()
Parses a string with respect to previously registered options.
 o registerOption(String)
Adds an option to be parsed.
 o registerOption(String, int)
Adds an option to be parsed.
 o registerOptions(String[], int[])
Adds options to be parsed.

Constructors

 o 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.
 o 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

 o 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.
 o 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.

Methods

 o 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.
 o 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.
 o 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.
 o parse
 public void parse() throws NotEnoughArgsException
Parses a string with respect to previously registered options.

 o getOptions
 public String[] getOptions()
Returns a string table with the option names. returns null if there is no option registered.

 o 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.
 o 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.
 o getArgsWithoutOption
 public String[] getArgsWithoutOption()
 o 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.
 o countOptions
 public int countOptions()
Returns the number of options parsed.

 o 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.
 o 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