org.apache.commons.cli2.option
Class SourceDestArgument

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

public class SourceDestArgument
extends ArgumentImpl

An Argument implementation that allows a variable size Argument to precede a fixed size argument. The canonical example of it's use is in the unix cp command where a number of source can be specified with exactly one destination specfied at the end.


Field Summary
 
Fields inherited from class org.apache.commons.cli2.option.ArgumentImpl
DEFAULT_CONSUME_REMAINING, DEFAULT_INITIAL_SEPARATOR, DEFAULT_SUBSEQUENT_SEPARATOR
 
Constructor Summary
SourceDestArgument(Argument source, Argument dest)
          Creates a SourceDestArgument using defaults where possible.
SourceDestArgument(Argument source, Argument dest, char initialSeparator, char subsequentSeparator, String consumeRemaining, List defaultValues)
          Creates a SourceDestArgument 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 arg)
          Indicates whether this Option will be able to process the particular argument.
 List helpLines(int depth, Set helpSettings, Comparator comp)
          Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.
 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.ArgumentImpl
defaults, defaultValues, getConsumeRemaining, getDefaultValues, getDescription, getInitialSeparator, getMaximum, getMinimum, getPreferredName, getPrefixes, getSubsequentSeparator, getTriggers, getValidator, isRequired, process, processValues, stripBoundaryQuotes, validate
 
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
 

Constructor Detail

SourceDestArgument

public SourceDestArgument(Argument source,
                          Argument dest)
Creates a SourceDestArgument using defaults where possible.

Parameters:
source - the variable size Argument
dest - the fixed size Argument

SourceDestArgument

public SourceDestArgument(Argument source,
                          Argument dest,
                          char initialSeparator,
                          char subsequentSeparator,
                          String consumeRemaining,
                          List defaultValues)
Creates a SourceDestArgument using the specified parameters.

Parameters:
source - the variable size Argument
dest - the fixed size Argument
initialSeparator - the inistial separator to use
subsequentSeparator - the subsequent separator to use
consumeRemaining - the token triggering consume remaining behaviour
defaultValues - the default values for the SourceDestArgument
Method Detail

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
Overrides:
appendUsage in class ArgumentImpl
Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options

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
Overrides:
helpLines in class ArgumentImpl
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

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
Overrides:
validate in class ArgumentImpl
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)

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
Overrides:
canProcess in class ArgumentImpl
Parameters:
commandLine - The CommandLine to check
arg - The argument to be tested
Returns:
true if the argument can be processed by this Option


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