net.dpml.cli.option
Class PropertyOption

java.lang.Object
  extended bynet.dpml.cli.option.OptionImpl
      extended bynet.dpml.cli.option.PropertyOption
All Implemented Interfaces:
Option

public class PropertyOption
extends OptionImpl

Handles the java style "-Dprop=value" opions

Version:
1.0.0
Author:
Digital Product Meta Library

Field Summary
static String DEFAULT_DESCRIPTION
          The default property option description.
static String DEFAULT_OPTION_STRING
          The default property option name.
static PropertyOption INSTANCE
          A default PropertyOption instance
 
Constructor Summary
PropertyOption()
          Creates a new PropertyOption using the default settings of a "-D" trigger and an id of 'D'
PropertyOption(String optionString, String description, int id)
          Creates a new PropertyOption using the specified parameters
 
Method Summary
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
          Appends usage information to the specified StringBuffer
 boolean canProcess(WriteableCommandLine commandLine, String argument)
          Indicates whether this Option will be able to process the particular argument.
 String getDescription()
          Returns a description of the option.
 String getPreferredName()
          The preferred name of an option is used for generating help and usage information.
 Set getPrefixes()
          Identifies the argument prefixes that should be considered options.
 Set getTriggers()
          Identifies the argument prefixes that should trigger this option.
 List helpLines(int depth, Set helpSettings, Comparator comp)
          Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.
 void process(WriteableCommandLine commandLine, ListIterator arguments)
          Processes String arguments into a CommandLine.
 void validate(WriteableCommandLine commandLine)
          Checks that the supplied CommandLine is valid with respect to this option.
 
Methods inherited from class net.dpml.cli.option.OptionImpl
canProcess, checkPrefixes, defaults, equals, findOption, getId, hashCode, isRequired, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_OPTION_STRING

public static final String DEFAULT_OPTION_STRING
The default property option name.

See Also:
Constant Field Values

DEFAULT_DESCRIPTION

public static final String DEFAULT_DESCRIPTION
The default property option description.

See Also:
Constant Field Values

INSTANCE

public static final PropertyOption INSTANCE
A default PropertyOption instance

Constructor Detail

PropertyOption

public PropertyOption()
Creates a new PropertyOption using the default settings of a "-D" trigger and an id of 'D'


PropertyOption

public PropertyOption(String optionString,
                      String description,
                      int id)
Creates a new PropertyOption using the specified parameters

Parameters:
optionString - the trigger for the Option
description - the description of the Option
id - the id of the Option
Method Detail

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          String argument)
Indicates whether this Option will be able to process the particular argument.

Parameters:
commandLine - the CommandLine object to store defaults in
argument - the argument to be tested
Returns:
true if the argument can be processed by this Option

getPrefixes

public Set getPrefixes()
Identifies the argument prefixes that should be considered options. This is used to identify whether a given string looks like an option or an argument value. Typically an option would return the set [--,-] while switches might offer [-,+]. The returned Set must not be null.

Returns:
The set of prefixes for this Option

process

public void process(WriteableCommandLine commandLine,
                    ListIterator arguments)
             throws OptionException
Processes String arguments into a CommandLine. The iterator will initially point at the first argument to be processed and at the end of the method should point to the first argument not processed. This method MUST process at least one argument from the ListIterator.

Parameters:
commandLine - the CommandLine object to store results in
arguments - the arguments to process
Throws:
OptionException - if any problems occur

getTriggers

public Set getTriggers()
Identifies the argument prefixes that should trigger this option. This is used to decide which of many Options should be tried when processing a given argument string. The returned Set must not be null.

Returns:
The set of triggers for this Option

validate

public void validate(WriteableCommandLine commandLine)
              throws OptionException
Checks that the supplied CommandLine is valid with respect to this option.

Parameters:
commandLine - the CommandLine to check.
Throws:
OptionException - if the CommandLine is not valid.

appendUsage

public void appendUsage(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp)
Appends usage information to the specified StringBuffer

Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options

getPreferredName

public String getPreferredName()
The preferred name of an option is used for generating help and usage information.

Returns:
The preferred name of the option

getDescription

public String getDescription()
Returns a description of the option. This string is used to build help messages as in the HelpFormatter.

Returns:
a description of the option.
See Also:
HelpFormatter

helpLines

public List helpLines(int depth,
                      Set helpSettings,
                      Comparator comp)
Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.

Parameters:
depth - the initial indent depth
helpSettings - the HelpSettings that should be applied
comp - a comparator used to sort options when applicable.
Returns:
a List of HelpLineImpl objects
See Also:
HelpLine, HelpFormatter