org.apache.commons.cli2.option
Class ArgumentImpl

java.lang.Object
  extended by org.apache.commons.cli2.option.OptionImpl
      extended by org.apache.commons.cli2.option.ArgumentImpl
All Implemented Interfaces:
Argument, Option
Direct Known Subclasses:
SourceDestArgument

public class ArgumentImpl
extends OptionImpl
implements Argument

An implementation of an Argument.


Field Summary
static String DEFAULT_CONSUME_REMAINING
          The default token to indicate that remaining arguments should be consumed as values.
static char DEFAULT_INITIAL_SEPARATOR
          The default value for the initial separator char.
static char DEFAULT_SUBSEQUENT_SEPARATOR
          The default value for the subsequent separator char.
 
Constructor Summary
ArgumentImpl(String name, String description, int minimum, int maximum, char initialSeparator, char subsequentSeparator, Validator validator, String consumeRemaining, List valueDefaults, int id)
          Creates a new Argument instance.
 
Method Summary
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
          Appends usage information to the specified StringBuffer
 boolean canProcess(WriteableCommandLine commandLine, String arg)
          Indicates whether this Option will be able to process the particular argument.
 void defaults(WriteableCommandLine commandLine)
          Adds defaults to a CommandLine.
 void defaultValues(WriteableCommandLine commandLine, Option option)
          Adds defaults to a CommandLine.
 String getConsumeRemaining()
           
 List getDefaultValues()
           
 String getDescription()
          Returns a description of the option.
 char getInitialSeparator()
          Returns the initial separator character or '\0' if no character has been set.
 int getMaximum()
          Retrieves the maximum number of values acceptable for a valid Argument
 int getMinimum()
          Retrieves the minimum number of values required for a valid Argument
 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.
 char getSubsequentSeparator()
           
 Set getTriggers()
          Identifies the argument prefixes that should trigger this option.
 Validator getValidator()
           
 List helpLines(int depth, Set helpSettings, Comparator comp)
          Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.
 boolean isRequired()
          Indicates whether this option is required to be present.
 void process(WriteableCommandLine commandLine, ListIterator args)
          Processes String arguments into a CommandLine.
 void processValues(WriteableCommandLine commandLine, ListIterator arguments, Option option)
          Processes the "README" style element of the argument.
 String stripBoundaryQuotes(String token)
          If there are any leading or trailing quotes remove them from the specified token.
 void validate(WriteableCommandLine commandLine)
          Checks that the supplied CommandLine is valid with respect to this option.
 void validate(WriteableCommandLine commandLine, Option option)
          Performs any necessary validation on the values added to the CommandLine.
 
Methods inherited from class org.apache.commons.cli2.option.OptionImpl
canProcess, checkPrefixes, equals, findOption, getId, getParent, hashCode, setParent, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.cli2.Option
canProcess, findOption, getId, getParent, setParent
 

Field Detail

DEFAULT_INITIAL_SEPARATOR

public static final char DEFAULT_INITIAL_SEPARATOR
The default value for the initial separator char.

See Also:
Constant Field Values

DEFAULT_SUBSEQUENT_SEPARATOR

public static final char DEFAULT_SUBSEQUENT_SEPARATOR
The default value for the subsequent separator char.

See Also:
Constant Field Values

DEFAULT_CONSUME_REMAINING

public static final String DEFAULT_CONSUME_REMAINING
The default token to indicate that remaining arguments should be consumed as values.

See Also:
Constant Field Values
Constructor Detail

ArgumentImpl

public ArgumentImpl(String name,
                    String description,
                    int minimum,
                    int maximum,
                    char initialSeparator,
                    char subsequentSeparator,
                    Validator validator,
                    String consumeRemaining,
                    List valueDefaults,
                    int id)
Creates a new Argument instance.

Parameters:
name - The name of the argument
description - A description of the argument
minimum - The minimum number of values needed to be valid
maximum - The maximum number of values allowed to be valid
initialSeparator - The char separating option from value
subsequentSeparator - The char separating values from each other
validator - The object responsible for validating the values
consumeRemaining - The String used for the "consuming option" group
valueDefaults - The values to be used if none are specified.
id - The id of the option, 0 implies automatic assignment.
See Also:
OptionImpl.OptionImpl(int,boolean)
Method Detail

getPreferredName

public String getPreferredName()
Description copied from interface: Option
The preferred name of an option is used for generating help and usage information.

Specified by:
getPreferredName in interface Option
Returns:
The preferred name of the option

processValues

public void processValues(WriteableCommandLine commandLine,
                          ListIterator arguments,
                          Option option)
                   throws OptionException
Description copied from interface: Argument
Processes the "README" style element of the argument. Values identified should be added to the CommandLine object in association with this Argument.

Specified by:
processValues in interface Argument
Parameters:
commandLine - The CommandLine object to store results in.
arguments - The arguments to process.
option - The option to register value against.
Throws:
OptionException - if any problems occur.
See Also:
WriteableCommandLine.addValue(Option,Object)

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          String arg)
Description copied from interface: Option
Indicates whether this Option will be able to process the particular argument.

Specified by:
canProcess in interface Option
Parameters:
commandLine - The CommandLine to check
arg - The argument to be tested
Returns:
true if the argument can be processed by this Option

getPrefixes

public Set getPrefixes()
Description copied from interface: Option
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.

Specified by:
getPrefixes in interface Option
Returns:
The set of prefixes for this Option

process

public void process(WriteableCommandLine commandLine,
                    ListIterator args)
             throws OptionException
Description copied from interface: Option
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.

Specified by:
process in interface Option
Parameters:
commandLine - The CommandLine object to store results in
args - The arguments to process
Throws:
OptionException - if any problems occur

getInitialSeparator

public char getInitialSeparator()
Description copied from interface: Argument
Returns the initial separator character or '\0' if no character has been set.

Specified by:
getInitialSeparator in interface Argument
Returns:
char the initial separator character

getSubsequentSeparator

public char getSubsequentSeparator()

getTriggers

public Set getTriggers()
Description copied from interface: Option
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.

Specified by:
getTriggers in interface Option
Returns:
The set of triggers for this Option

getConsumeRemaining

public String getConsumeRemaining()

getDefaultValues

public List getDefaultValues()

getValidator

public Validator getValidator()

validate

public void validate(WriteableCommandLine commandLine)
              throws OptionException
Description copied from interface: Option
Checks that the supplied CommandLine is valid with respect to this option.

Specified by:
validate in interface Option
Parameters:
commandLine - The CommandLine to check.
Throws:
OptionException - if the CommandLine is not valid.

validate

public void validate(WriteableCommandLine commandLine,
                     Option option)
              throws OptionException
Description copied from interface: Argument
Performs any necessary validation on the values added to the CommandLine. Validation will typically involve using the CommandLine.getValues(option) method to retrieve the values and then either checking each value. Optionally the String value can be replaced by another Object such as a Number instance or a File instance.

Specified by:
validate in interface Argument
Parameters:
commandLine - The CommandLine object to query.
option - The option to lookup values with.
Throws:
OptionException - if any problems occur.
See Also:
CommandLine.getValues(Option)

appendUsage

public void appendUsage(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp)
Description copied from interface: Option
Appends usage information to the specified StringBuffer

Specified by:
appendUsage in interface Option
Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options

getDescription

public String getDescription()
Description copied from interface: Option
Returns a description of the option. This string is used to build help messages as in the HelpFormatter.

Specified by:
getDescription in interface Option
Returns:
a description of the option.
See Also:
HelpFormatter

helpLines

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

Specified by:
helpLines in interface Option
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

getMaximum

public int getMaximum()
Description copied from interface: Argument
Retrieves the maximum number of values acceptable for a valid Argument

Specified by:
getMaximum in interface Argument
Returns:
the maximum number of values

getMinimum

public int getMinimum()
Description copied from interface: Argument
Retrieves the minimum number of values required for a valid Argument

Specified by:
getMinimum in interface Argument
Returns:
the minimum number of values

stripBoundaryQuotes

public String stripBoundaryQuotes(String token)
If there are any leading or trailing quotes remove them from the specified token.

Parameters:
token - the token to strip leading and trailing quotes
Returns:
String the possibly modified token

isRequired

public boolean isRequired()
Description copied from interface: Option
Indicates whether this option is required to be present.

Specified by:
isRequired in interface Argument
Specified by:
isRequired in interface Option
Overrides:
isRequired in class OptionImpl
Returns:
true iff the CommandLine will be invalid without this Option
See Also:
Argument.getMinimum(), Argument.getMaximum()

defaults

public void defaults(WriteableCommandLine commandLine)
Description copied from interface: Option
Adds defaults to a CommandLine. Any defaults for this option are applied as well as the defaults for any contained options

Specified by:
defaults in interface Option
Overrides:
defaults in class OptionImpl
Parameters:
commandLine - The CommandLine object to store defaults in

defaultValues

public void defaultValues(WriteableCommandLine commandLine,
                          Option option)
Description copied from interface: Argument
Adds defaults to a CommandLine.

Specified by:
defaultValues in interface Argument
Parameters:
commandLine - The CommandLine object to store defaults in.
option - The Option to store the defaults against.


Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.