gnu.classpath.tools.getopt
Class Option

java.lang.Object
  extended by gnu.classpath.tools.getopt.Option
Direct Known Subclasses:
LogOption

public abstract class Option
extends Object

This is the base class representing an option. An option can have a short form. This is a single character, like '-x'. An option can have a long form, like '--verbose'; if the parser is working in "long option only" mode, then a long flag has a single dash, like '-verbose'. Both a long and a short form may be specified; it is not valid to have neither. A description is mandatory for options; this is used to automatically generate '--help' output. An option which takes an argument and which has a short form can also be "joined", in this case the option's argument can either be separated, like "-I path" or joined with the short option name, like "-Ipath".


Field Summary
private  String argumentName
           
private  String description
           
private  boolean joined
           
private  String longName
           
private  char shortName
           
 
Constructor Summary
protected Option(char shortName, String description)
          Create a new option with the given short name and description.
protected Option(char shortName, String description, String argumentName)
          Create a new option with the given short name and description.
protected Option(char shortName, String description, String argumentName, boolean joined)
          Create a new option with the given short name and description.
protected Option(String longName, char shortName, String description)
          Create a new option with the given short and long names and description.
protected Option(String longName, char shortName, String description, String argumentName)
          Create a new option with the given short and long names and description.
protected Option(String longName, char shortName, String description, String argumentName, boolean joined)
          Create a new option with the given short and long names and description.
protected Option(String longName, String description)
          Create a new option with the given long name and description.
protected Option(String longName, String description, String argumentName)
          Create a new option with the given long name and description.
 
Method Summary
 String getArgumentName()
          Return the name of the argument.
 String getDescription()
          Return the description of the option.
 String getLongName()
          Return the long name of the option, or null if none.
 char getShortName()
          Return the short name of the option, or \0 if none.
 boolean getTakesArgument()
          Return true if the argument takes an option.
 boolean isJoined()
          Return true if this is a "joined" option, false otherwise.
abstract  void parsed(String argument)
          This is called by the parser when this option is recognized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shortName

private char shortName

longName

private String longName

description

private String description

argumentName

private String argumentName

joined

private boolean joined
Constructor Detail

Option

protected Option(char shortName,
                 String description)
Create a new option with the given short name and description.

Parameters:
shortName - the short name
description - the description

Option

protected Option(char shortName,
                 String description,
                 String argumentName)
Create a new option with the given short name and description.

Parameters:
shortName - the short name
description - the description
argumentName - the descriptive name of the argument, if this option takes an argument; otherwise null

Option

protected Option(char shortName,
                 String description,
                 String argumentName,
                 boolean joined)
Create a new option with the given short name and description.

Parameters:
shortName - the short name
description - the description
argumentName - the descriptive name of the argument, if this option takes an argument; otherwise null
joined - true if the short option is joined to its argument

Option

protected Option(String longName,
                 String description)
Create a new option with the given long name and description. The long name should be specified without any leading dashes.

Parameters:
longName - the long name
description - the description

Option

protected Option(String longName,
                 String description,
                 String argumentName)
Create a new option with the given long name and description. The long name should be specified without any leading dashes.

Parameters:
longName - the long name
description - the description
argumentName - the descriptive name of the argument, if this option takes an argument; otherwise null

Option

protected Option(String longName,
                 char shortName,
                 String description)
Create a new option with the given short and long names and description. The long name should be specified without any leading dashes.

Parameters:
longName - the long name
shortName - the short name
description - the description

Option

protected Option(String longName,
                 char shortName,
                 String description,
                 String argumentName)
Create a new option with the given short and long names and description. The long name should be specified without any leading dashes.

Parameters:
longName - the long name
shortName - the short name
description - the description
argumentName - the descriptive name of the argument, if this option takes an argument; otherwise null

Option

protected Option(String longName,
                 char shortName,
                 String description,
                 String argumentName,
                 boolean joined)
Create a new option with the given short and long names and description. The long name should be specified without any leading dashes.

Parameters:
longName - the long name
shortName - the short name
description - the description
argumentName - the descriptive name of the argument, if this option takes an argument; otherwise null
joined - true if the short option is joined to its argument
Method Detail

getShortName

public char getShortName()
Return the short name of the option, or \0 if none.


getLongName

public String getLongName()
Return the long name of the option, or null if none.


getTakesArgument

public boolean getTakesArgument()
Return true if the argument takes an option.


getArgumentName

public String getArgumentName()
Return the name of the argument. If the option does not take an argument, returns null.


getDescription

public String getDescription()
Return the description of the option.


isJoined

public boolean isJoined()
Return true if this is a "joined" option, false otherwise. Only the short form of an option can be joined; this will always return false for an option which does not have a short form.


parsed

public abstract void parsed(String argument)
                     throws OptionException
This is called by the parser when this option is recognized. It may be called multiple times during a single parse. If this option takes an argument, the argument will be passed in. Otherwise the argument will be null.

Parameters:
argument - the argument
Throws:
OptionException - if the option or its argument is somehow invalid