kiwi.util
Class CommandLineParser

java.lang.Object
  |
  +--kiwi.util.CommandLineParser

public class CommandLineParser
extends Object

A class that does approximately what getopt() does in C. For use in Java applications. Includes GNU longopt support.

Version:
2.4 (3/98)
Author:
Paul Jimenez et al.

Field Summary
protected  Hashtable optionlist
          The internal storage of options.
 String[] params
          The list of parameters that weren't arguments to options.
 
Constructor Summary
CommandLineParser(String[] argv, String validFlags, String validOptions)
          Construct a new CommandLineParser without longopt support.
CommandLineParser(String[] argv, String validFlags, String validOptions, String[] validLongFlags, String[] validLongOptions)
          Construct a new CommandLineParser.
CommandLineParser(String[] argv, String validFlags, String validOptions, String requiredOptions, String[] validLongFlags, String[] validLongOptions, String[] requiredLongOptions)
          Construct a new CommandLineParser with required options that must have parameters if specified.
 
Method Summary
 String getOption(Character option)
          Get the value of the named option.
 String getOption(String option)
          Get the value of the named option.
 boolean hasOption(Character option)
          Check if the command line contains the named option.
 boolean hasOption(String option)
          Check if the command line contains the named option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

params

public String[] params
The list of parameters that weren't arguments to options.

optionlist

protected Hashtable optionlist
The internal storage of options.
Constructor Detail

CommandLineParser

public CommandLineParser(String[] argv,
                         String validFlags,
                         String validOptions,
                         String[] validLongFlags,
                         String[] validLongOptions)
                  throws InvalidCommandLineArgumentException
Construct a new CommandLineParser.
Parameters:
argv - Array of strings (usually argv).
validFlags - A string of valid options that don't take arguments.
validOptions - A string of valid options that take (optional) arguments.
validLongFlags - Array of strings that are valid options that don't take arguments.
validLongOptions - Array of strings that are valid options that take (optional) arguments.
Throws:
InvalidCommandLineArgumentException - Iff an invalid argument is found on the command line.

CommandLineParser

public CommandLineParser(String[] argv,
                         String validFlags,
                         String validOptions)
                  throws InvalidCommandLineArgumentException
Construct a new CommandLineParser without longopt support.
Parameters:
argv - Array of strings (usually argv).
validFlags - A string of valid options that don't take arguments.
validOptions - A string of valid options that take (optional) arguments.
Throws:
InvalidCommandLineArgumentException - Iff an invalid argument is found on the commandline.

CommandLineParser

public CommandLineParser(String[] argv,
                         String validFlags,
                         String validOptions,
                         String requiredOptions,
                         String[] validLongFlags,
                         String[] validLongOptions,
                         String[] requiredLongOptions)
                  throws InvalidCommandLineArgumentException,
                         MissingCommandLineArgumentException
Construct a new CommandLineParser with required options that must have parameters if specified.
Parameters:
argv - Array of strings (usually argv).
validFlags - A string of valid options that don't take arguments
validOptions - A string of valid options that take (optional) arguments.
requiredOptions - A string of valid options that must be provided with arguments.
validlongflags - Array of strings that are valid options that don't take arguments.
validLongOptions - array of strings that are valid options that take (optional) arguments.
requiredLongOptions - Array of strings that are valid options that must be provided with arguments.
Throws:
InvalidCommandLineArgumentException - Iff an invalid argument is found on the command line.
MissingCommandLineArgumentException - Iff a required option is specified without an option.
Method Detail

hasOption

public boolean hasOption(Character option)
Check if the command line contains the named option.
Parameters:
option - The (short) option.

hasOption

public boolean hasOption(String option)
Check if the command line contains the named option.
Parameters:
option - The (long) option.

getOption

public String getOption(Character option)
Get the value of the named option.
Parameters:
option - The (short) option.

getOption

public String getOption(String option)
Get the value of the named option.
Parameters:
option - The (long) option.