org.apache.avalon.excalibur.cli
Class CLArgsParser

java.lang.Object
  |
  +--org.apache.avalon.excalibur.cli.CLArgsParser

public final class CLArgsParser
extends java.lang.Object

Parser for command line arguments. This parses command lines according to the standard (?) of gnu utilities. Note: This is still used in 1.1 libraries so do not add 1.2+ dependancies.

Author:
Peter Donald

Inner Class Summary
protected  class CLArgsParser.Token
           
 
Field Summary
protected static char[] ARG_SEPERATORS
           
protected static char[] ARG2_SEPERATORS
           
protected  int argIndex
           
protected  java.lang.String[] args
           
protected  char ch
           
protected static int INVALID
           
protected  boolean isLong
           
protected  ParserControl m_control
           
protected  java.lang.String m_errorMessage
           
protected  int m_lastChar
           
protected  int m_lastOptionId
           
protected  CLOption m_option
           
protected  CLOptionDescriptor[] m_optionDescriptors
           
protected  java.util.Vector m_options
           
protected  int m_state
           
protected  java.lang.String[] m_unparsedArgs
           
protected static char[] NULL_SEPERATORS
           
protected  int stringIndex
           
protected  int stringLength
           
protected static int TOKEN_SEPERATOR
           
protected static int TOKEN_STRING
           
 
Constructor Summary
CLArgsParser(java.lang.String[] args, CLOptionDescriptor[] optionDescriptors)
          Create a parser that can deals with options and parses certain args.
CLArgsParser(java.lang.String[] args, CLOptionDescriptor[] optionDescriptors, ParserControl control)
          Create a parser that can deals with options and parses certain args.
 
Method Summary
protected  void addOption(CLOption option)
           
protected  void checkIncompatabilities(java.util.Vector arguments)
          Check for duplicates of an option.
protected  void checkIncompatable(java.util.Vector arguments, int[] incompatable, int original)
           
protected  java.lang.String describeDualOption(int id)
           
 java.util.Vector getArguments()
          Retrieve a list of options that were parsed from command list.
protected  char getChar()
           
 java.lang.String getErrorString()
          Retrieve an error message that occured during parsing if one existed.
protected  java.lang.String getOptionDescription(CLOptionDescriptor descriptor)
           
 java.lang.String[] getUnparsedArgs()
           
protected  CLArgsParser.Token nextToken(char[] seperators)
           
protected  void parse()
          Actually parse arguments
protected  boolean parseArguments()
           
protected  void parseNormal()
          Parse Options from Normal mode.
protected  void parseOption(CLOptionDescriptor descriptor, java.lang.String optionString)
           
protected  void parseShortOption()
           
protected  char peekAtChar()
           
protected  java.lang.String[] subArray(java.lang.String[] array, int index, int charIndex)
          Create a string array that is subset of input array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOKEN_SEPERATOR

protected static final int TOKEN_SEPERATOR

TOKEN_STRING

protected static final int TOKEN_STRING

ARG2_SEPERATORS

protected static final char[] ARG2_SEPERATORS

ARG_SEPERATORS

protected static final char[] ARG_SEPERATORS

NULL_SEPERATORS

protected static final char[] NULL_SEPERATORS

m_optionDescriptors

protected final CLOptionDescriptor[] m_optionDescriptors

m_options

protected final java.util.Vector m_options

m_control

protected final ParserControl m_control

m_errorMessage

protected java.lang.String m_errorMessage

m_unparsedArgs

protected java.lang.String[] m_unparsedArgs

ch

protected char ch

args

protected java.lang.String[] args

isLong

protected boolean isLong

argIndex

protected int argIndex

stringIndex

protected int stringIndex

stringLength

protected int stringLength

INVALID

protected static final int INVALID

m_lastChar

protected int m_lastChar

m_lastOptionId

protected int m_lastOptionId

m_option

protected CLOption m_option

m_state

protected int m_state
Constructor Detail

CLArgsParser

public CLArgsParser(java.lang.String[] args,
                    CLOptionDescriptor[] optionDescriptors,
                    ParserControl control)
Create a parser that can deals with options and parses certain args.
Parameters:
args[] - the args
optionDescriptors[] - the option descriptors

CLArgsParser

public CLArgsParser(java.lang.String[] args,
                    CLOptionDescriptor[] optionDescriptors)
Create a parser that can deals with options and parses certain args.
Parameters:
args[] - the args
optionDescriptors[] - the option descriptors
Method Detail

getUnparsedArgs

public java.lang.String[] getUnparsedArgs()

getArguments

public java.util.Vector getArguments()
Retrieve a list of options that were parsed from command list.
Returns:
the list of options

getErrorString

public java.lang.String getErrorString()
Retrieve an error message that occured during parsing if one existed.
Returns:
the error string

checkIncompatabilities

protected void checkIncompatabilities(java.util.Vector arguments)
                               throws java.text.ParseException
Check for duplicates of an option. It is an error to have duplicates unless appropriate flags is set in descriptor.
Parameters:
arguments - the arguments

checkIncompatable

protected void checkIncompatable(java.util.Vector arguments,
                                 int[] incompatable,
                                 int original)
                          throws java.text.ParseException

describeDualOption

protected java.lang.String describeDualOption(int id)

subArray

protected java.lang.String[] subArray(java.lang.String[] array,
                                      int index,
                                      int charIndex)
Create a string array that is subset of input array. The sub-array should start at array entry indicated by index. That array element should only include characters from charIndex onwards.
Parameters:
array[] - the original array
index - the cut-point in array
charIndex - the cut-point in element of array
Returns:
the result array

parse

protected void parse()
              throws java.text.ParseException
Actually parse arguments
Parameters:
args[] - arguments

getOptionDescription

protected final java.lang.String getOptionDescription(CLOptionDescriptor descriptor)

peekAtChar

protected final char peekAtChar()

getChar

protected final char getChar()

nextToken

protected final CLArgsParser.Token nextToken(char[] seperators)

addOption

protected void addOption(CLOption option)

parseOption

protected void parseOption(CLOptionDescriptor descriptor,
                           java.lang.String optionString)
                    throws java.text.ParseException

parseShortOption

protected void parseShortOption()
                         throws java.text.ParseException

parseArguments

protected boolean parseArguments()
                          throws java.text.ParseException

parseNormal

protected void parseNormal()
                    throws java.text.ParseException
Parse Options from Normal mode.


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.