gnu.classpath.tools.getopt
Class Parser

java.lang.Object
  extended by gnu.classpath.tools.getopt.Parser

public class Parser
extends Object

An instance of this class is used to parse command-line options. It does "GNU style" argument recognition and also automatically handles "--help" and "--version" processing. It can also be put in "long option only" mode. In this mode long options are recognized with a single dash (as well as a double dash) and strings of options like "-abc" are never parsed as a collection of short options.


Field Summary
static int MAX_LINE_LENGTH
          The maximum right column position.
 
Constructor Summary
Parser(String programName, String versionString)
          Create a new parser.
Parser(String programName, String versionString, boolean longOnly)
          Create a new parser.
 
Method Summary
 void add(Option opt)
          Add an option to this parser.
 void add(OptionGroup group)
          Add an option group to this parser.
 String[] parse(String[] inArgs)
          Parse a command line.
 void parse(String[] inArgs, FileArgumentCallback files)
          Parse a command line.
 void printHelp()
           
 void setFooter(String footerText)
          Set the footer text that is printed by --help.
 void setHeader(String headerText)
          Set the header text that is printed by --help.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_LINE_LENGTH

public static final int MAX_LINE_LENGTH
The maximum right column position.

See Also:
Constant Field Values
Constructor Detail

Parser

public Parser(String programName,
              String versionString)
Create a new parser. The program name is used when printing error messages. The version string is printed verbatim in response to "--version".

Parameters:
programName - the name of the program
versionString - the program's version information

Parser

public Parser(String programName,
              String versionString,
              boolean longOnly)
Create a new parser. The program name is used when printing error messages. The version string is printed verbatim in response to "--version".

Parameters:
programName - the name of the program
versionString - the program's version information
longOnly - true if the parser should work in long-option-only mode
Method Detail

setHeader

public void setHeader(String headerText)
Set the header text that is printed by --help.

Parameters:
headerText - the header text

setFooter

public void setFooter(String footerText)
Set the footer text that is printed by --help.

Parameters:
footerText - the footer text

add

public void add(Option opt)
Add an option to this parser. The option is added to the default option group; this affects where it is placed in the help output.

Parameters:
opt - the option

add

public void add(OptionGroup group)
Add an option group to this parser. All the options in this group will be recognized by the parser.

Parameters:
group - the option group

printHelp

public void printHelp()

parse

public void parse(String[] inArgs,
                  FileArgumentCallback files)
Parse a command line. Any files which are found will be passed to the file argument callback. This method will exit on error or when --help or --version is specified.

Parameters:
inArgs - the command-line arguments
files - the file argument callback

parse

public String[] parse(String[] inArgs)
Parse a command line. Any files which are found will be returned. This method will exit on error or when --help or --version is specified.

Parameters:
inArgs - the command-line arguments