org.apache.commons.cli
Class Parser

java.lang.Object
  |
  +--org.apache.commons.cli.Parser
Direct Known Subclasses:
BasicParser, GnuParser, PosixParser

public abstract class Parser
extends java.lang.Object
implements CommandLineParser

Parser creates CommandLines.

Version:
$Revision: 1.7 $
Author:
John Keyes (john at integralsource.com)
See Also:
Parser

Field Summary
private  CommandLine cmd
          commandline instance
private  Options options
          current Options
private  java.util.List requiredOptions
          list of required options strings
 
Constructor Summary
Parser()
           
 
Method Summary
private  void checkRequiredOptions()
          Throws a MissingOptionException if all of the required options are no present.
protected abstract  java.lang.String[] flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)
          Subclasses must implement this method to reduce the arguments that have been passed to the parse method.
 CommandLine parse(Options options, java.lang.String[] arguments)
          Parses the specified arguments based on the specifed Options.
 CommandLine parse(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)
          Parses the specified arguments based on the specifed Options.
 void processArgs(Option opt, java.util.ListIterator iter)
           
private  void processOption(java.lang.String arg, java.util.ListIterator iter)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cmd

private CommandLine cmd
commandline instance

options

private Options options
current Options

requiredOptions

private java.util.List requiredOptions
list of required options strings
Constructor Detail

Parser

public Parser()
Method Detail

flatten

protected abstract java.lang.String[] flatten(Options opts,
                                              java.lang.String[] arguments,
                                              boolean stopAtNonOption)

Subclasses must implement this method to reduce the arguments that have been passed to the parse method.

Parameters:
opts - The Options to parse the arguments by.
args - The arguments that have to be flattened.
stopAtNonOption - specifies whether to stop flattening when a non option has been encountered
Returns:
a String array of the flattened arguments

parse

public CommandLine parse(Options options,
                         java.lang.String[] arguments)
                  throws ParseException

Parses the specified arguments based on the specifed Options.

Specified by:
parse in interface CommandLineParser
Parameters:
options - the Options
arguments - the arguments
Returns:
the CommandLine
Throws:
ParseException - if an error occurs when parsing the arguments.

parse

public CommandLine parse(Options opts,
                         java.lang.String[] arguments,
                         boolean stopAtNonOption)
                  throws ParseException

Parses the specified arguments based on the specifed Options.

Specified by:
parse in interface CommandLineParser
Parameters:
options - the Options
arguments - the arguments
stopAtNonOption - specifies whether to stop interpreting the arguments when a non option has been encountered and to add them to the CommandLines args list.
Returns:
the CommandLine
Throws:
ParseException - if an error occurs when parsing the arguments.

checkRequiredOptions

private void checkRequiredOptions()
                           throws MissingOptionException

Throws a MissingOptionException if all of the required options are no present.


processArgs

public void processArgs(Option opt,
                        java.util.ListIterator iter)
                 throws ParseException

processOption

private void processOption(java.lang.String arg,
                           java.util.ListIterator iter)
                    throws ParseException