Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
net.dpml.cli.option.OptionImpl
net.dpml.cli.option.ArgumentImpl
Field Summary | |
static String |
|
static char |
|
static char |
|
Constructor Summary | |
|
Method Summary | |
void |
|
boolean |
|
void |
|
void |
|
String |
|
List |
|
String |
|
char |
|
int |
|
int |
|
String |
|
Set |
|
char |
|
Set |
|
Validator |
|
List |
|
boolean |
|
void |
|
void |
|
String |
|
void |
|
void |
|
Methods inherited from class net.dpml.cli.option.OptionImpl | |
canProcess , checkPrefixes , defaults , equals , findOption , getId , hashCode , isRequired , toString |
public static final String DEFAULT_CONSUME_REMAINING
The default token to indicate that remaining arguments should be consumed as values.
public static final char DEFAULT_INITIAL_SEPARATOR
The default value for the initial separator char.
- Field Value:
- '\'
public static final char DEFAULT_SUBSEQUENT_SEPARATOR
The default value for the subsequent separator char.
- Field Value:
- '\'
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 argumentdescription
- a description of the argumentminimum
- the minimum number of values needed to be validmaximum
- the maximum number of values allowed to be validinitialSeparator
- the char separating option from valuesubsequentSeparator
- the char separating values from each othervalidator
- object responsible for validating the valuesconsumeRemaining
- String used for the "consuming option" groupvalueDefaults
- values to be used if none are specified.id
- the id of the option, 0 implies automatic assignment.
- See Also:
OptionImpl.OptionImpl(int,boolean)
public void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
Appends usage information to the specified StringBuffer
- Specified by:
- appendUsage in interface Option
- Parameters:
buffer
- the buffer to append tohelpSettings
- a set of display settings @see DisplaySettingcomp
- a comparator used to sort the Options
public boolean canProcess(WriteableCommandLine commandLine, String argument)
Indicates whether this Option will be able to process the particular argument.
- Specified by:
- canProcess in interface Option
- Parameters:
commandLine
- the CommandLine object to store defaults inargument
- the argument to be tested
- Returns:
- true if the argument can be processed by this Option
public void defaultValues(WriteableCommandLine commandLine, Option option)
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.
public void defaults(WriteableCommandLine commandLine)
Adds defaults to a CommandLine.
- Overrides:
- defaults in interface OptionImpl
- Parameters:
commandLine
- the CommandLine object to store defaults in.
public String getConsumeRemaining()
Return the consume remaining flag.
- Returns:
- the consume remaining flag
public List getDefaultValues()
Return the list of default values.
- Returns:
- the default values
public String getDescription()
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
public char getInitialSeparator()
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
public int getMaximum()
Retrieves the maximum number of values acceptable for a valid Argument
- Specified by:
- getMaximum in interface Argument
- Returns:
- the maximum number of values
public int getMinimum()
Retrieves the minimum number of values required for a valid Argument
- Specified by:
- getMinimum in interface Argument
- Returns:
- the minimum number of values
public String getPreferredName()
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
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.
- Specified by:
- getPrefixes in interface Option
- Returns:
- The set of prefixes for this Option
public char getSubsequentSeparator()
Returns the subsequent separator character.
- Returns:
- the subsequent separator character
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.
- Specified by:
- getTriggers in interface Option
- Returns:
- The set of triggers for this Option
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 depthhelpSettings
- the HelpSettings that should be appliedcomp
- a comparator used to sort options when applicable.
- Returns:
- a List of HelpLineImpl objects
- See Also:
HelpLine
,HelpFormatter
public boolean isRequired()
Indicates whether argument values must be present for the CommandLine to be valid.
- Specified by:
- isRequired in interface Argument
- isRequired in interface Option
- Overrides:
- isRequired in interface OptionImpl
- Returns:
- true iff the CommandLine will be invalid without at least one value
- See Also:
getMinimum()
,getMaximum()
public void process(WriteableCommandLine commandLine, ListIterator args) 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 inargs
- the arguments to process
- Throws:
OptionException
- if any problems occur
public void processValues(WriteableCommandLine commandLine, ListIterator arguments, Option option) throws OptionException
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.
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
public void validate(WriteableCommandLine commandLine) throws OptionException
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.
- Parameters:
commandLine
- The CommandLine object to query.
- Throws:
OptionException
- if any problems occur.
- See Also:
CommandLine.getValues(Option)
public void validate(WriteableCommandLine commandLine, Option option) throws OptionException
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.
- 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)