com.townleyenterprises.command
Class RepeatableCommandOption

java.lang.Object
  extended bycom.townleyenterprises.command.CommandOption
      extended bycom.townleyenterprises.command.RepeatableCommandOption
Direct Known Subclasses:
DelimitedCommandOption, JoinedCommandOption

public class RepeatableCommandOption
extends CommandOption

This class provides the basic support for repeatable command line arguments. This class can be used to allow a given argument to be supplied more than once on the command line.

Since:
2.0
Version:
$Id: RepeatableCommandOption.java,v 1.4 2004/07/28 10:33:58 atownley Exp $
Author:
Andrew S. Townley

Constructor Summary
RepeatableCommandOption(java.lang.String longName, char shortName, java.lang.String argHelp, java.lang.String argDesc)
          The constructor takes almost all of the parent class's arguments, but the assumption is that if it was a regular command option, it wouldn't be necessary to recognize it more than once.
RepeatableCommandOption(java.lang.String longName, char shortName, java.lang.String argHelp, java.lang.String argDesc, boolean show, java.lang.String def)
          This version of the constructor allows specifying if the argument is to be shown to the user and if the argument has a default value if it is not specified on the command line.
 
Method Summary
protected  void addArg(java.lang.String arg)
          This method is provided so that any derived classes can append arguments to the list.
 java.lang.String getArg()
          This method will return the last argument matched by this option rather than the collection of all the arguments.
 java.util.List getArgs()
          This method returns the arguments which have been matched by this instance.
 void optionMatched(java.lang.String arg)
          This method calls the parent class's version to ensure that the option behaves consistently with the rest of the system, but it collects each of the arguments so that they may be retrieved via the getArgs method.
 void reset()
          This method empties the list of all matched arguments in addition to any operations performed by the parent class.
 
Methods inherited from class com.townleyenterprises.command.CommandOption
execute, getArgumentDefault, getArgValue, getDescription, getExpectsArgument, getHelp, getLongName, getMatched, getName, getShortName, getShowArgInHelp, hashCode, parseOption, parseOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepeatableCommandOption

public RepeatableCommandOption(java.lang.String longName,
                               char shortName,
                               java.lang.String argHelp,
                               java.lang.String argDesc)
The constructor takes almost all of the parent class's arguments, but the assumption is that if it was a regular command option, it wouldn't be necessary to recognize it more than once. Therefore, this class assumes that there will be an argument each time it is matched by the command parser.

Parameters:
longName - the long name to be checked
shortName - the short, single character name
argHelp - the help string for the argument
argDesc - the long description of what the argument does

RepeatableCommandOption

public RepeatableCommandOption(java.lang.String longName,
                               char shortName,
                               java.lang.String argHelp,
                               java.lang.String argDesc,
                               boolean show,
                               java.lang.String def)
This version of the constructor allows specifying if the argument is to be shown to the user and if the argument has a default value if it is not specified on the command line.

Parameters:
longName - the long name to be checked
shortName - the short, single character name
argHelp - the help string for the argument
argDesc - the long description of what the argument does
show - true if should be shown in autohelp
def - the default value (informational only) of the argument if it is not specified.
Method Detail

getArg

public java.lang.String getArg()
This method will return the last argument matched by this option rather than the collection of all the arguments.

Overrides:
getArg in class CommandOption
Returns:
the argument or null if no argument was specified

optionMatched

public void optionMatched(java.lang.String arg)
This method calls the parent class's version to ensure that the option behaves consistently with the rest of the system, but it collects each of the arguments so that they may be retrieved via the getArgs method.

Overrides:
optionMatched in class CommandOption
Parameters:
arg - the argument (if expected)

getArgs

public java.util.List getArgs()
This method returns the arguments which have been matched by this instance.

Returns:
a copy of the matched arguments

reset

public void reset()
This method empties the list of all matched arguments in addition to any operations performed by the parent class.

Overrides:
reset in class CommandOption
Since:
2.1

addArg

protected void addArg(java.lang.String arg)
This method is provided so that any derived classes can append arguments to the list.

Parameters:
arg - the argument to be added


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.