|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opends.server.util.args.ArgumentParser
org.opends.server.util.args.SubCommandArgumentParser
public class SubCommandArgumentParser
This class defines a variant of the argument parser that can be used with applications that use subcommands to customize their behavior and that have a different set of options per subcommand (e.g, "cvs checkout" takes different options than "cvs commit"). This parser also has the ability to use global options that will always be applicable regardless of the subcommand in addition to the subcommand-specific arguments. There must not be any conflicts between the global options and the option for any subcommand, but it is allowed to re-use subcommand-specific options for different purposes between different subcommands.
Field Summary |
---|
Fields inherited from class org.opends.server.util.args.ArgumentParser |
---|
argumentGroups, defaultArgGroup, generalArgGroup, ioArgGroup, ldapArgGroup |
Constructor Summary | |
---|---|
SubCommandArgumentParser(java.lang.String mainClassName,
Message toolDescription,
boolean longArgumentsCaseSensitive)
Creates a new instance of this subcommand argument parser with no arguments. |
Method Summary | |
---|---|
void |
addGlobalArgument(Argument argument)
Adds the provided argument to the set of global arguments handled by this parser. |
void |
addGlobalArgument(Argument argument,
ArgumentGroup group)
Adds the provided argument to the set of global arguments handled by this parser. |
Argument |
getGlobalArgument(java.lang.String name)
Retrieves the global argument with the specified name. |
Argument |
getGlobalArgumentForLongID(java.lang.String longID)
Retrieves the global argument with the specified long identifier. |
Argument |
getGlobalArgumentForShortID(java.lang.Character shortID)
Retrieves the global argument with the specified short identifier. |
java.util.LinkedList<Argument> |
getGlobalArgumentList()
Retrieves the list of all global arguments that have been defined for this argument parser. |
java.util.HashMap<java.lang.String,Argument> |
getGlobalArgumentsByLongID()
Retrieves the set of global arguments mapped by the long identifier that may be used to reference them. |
java.util.HashMap<java.lang.Character,Argument> |
getGlobalArgumentsByShortID()
Retrieves the set of global arguments mapped by the short identifier that may be used to reference them. |
Message |
getHelpUsageReference()
Retrieves a string describing how the user can get more help. |
java.lang.String |
getMainClassName()
Retrieves the fully-qualified name of the Java class that should be invoked to launch the program with which this argument parser is associated. |
java.lang.String[] |
getRawArguments()
Retrieves the raw set of arguments that were provided. |
SubCommand |
getSubCommand()
Retrieves the subcommand that was selected in the set of command-line arguments. |
SubCommand |
getSubCommand(java.lang.String name)
Retrieves the subcommand with the specified name. |
java.util.SortedMap<java.lang.String,SubCommand> |
getSubCommands()
Retrieves the set of subcommands defined for this argument parser, referenced by subcommand name. |
void |
getSubCommandUsage(MessageBuilder buffer,
SubCommand subCommand)
Appends usage information for the specified subcommand to the provided buffer. |
Message |
getToolDescription()
Retrieves a human-readable description for this tool, which should be included at the top of the command-line usage information. |
java.util.ArrayList<java.lang.String> |
getTrailingArguments()
Retrieves the set of unnamed trailing arguments that were provided on the command line. |
java.lang.String |
getUsage()
Retrieves a string containing usage information based on the defined arguments. |
void |
getUsage(java.io.OutputStream outputStream)
Writes usage information based on the defined arguments to the provided output stream. |
boolean |
hasGlobalArgument(java.lang.String argumentName)
Indicates whether this argument parser contains a global argument with the specified name. |
boolean |
hasGlobalArgumentWithLongID(java.lang.String longID)
Indicates whether this argument parser has a global argument with the specified long ID. |
boolean |
hasGlobalArgumentWithShortID(java.lang.Character shortID)
Indicates whether this argument parser has a global argument with the specified short ID. |
boolean |
hasSubCommand(java.lang.String name)
Indicates whether this argument parser has a subcommand with the specified name. |
boolean |
isUsageArgumentPresent()
Returns whether the usage argument was provided or not. |
boolean |
isVersionArgumentPresent()
Returns whether the version argument was provided or not. |
boolean |
longArgumentsCaseSensitive()
Indicates whether subcommand names and long argument strings should be treated in a case-sensitive manner. |
void |
parseArguments(java.lang.String[] rawArguments)
Parses the provided set of arguments and updates the information associated with this parser accordingly. |
void |
parseArguments(java.lang.String[] rawArguments,
java.util.Properties argumentProperties)
Parses the provided set of arguments and updates the information associated with this parser accordingly. |
void |
parseArguments(java.lang.String[] rawArguments,
java.lang.String propertiesFile,
boolean requirePropertiesFile)
Parses the provided set of arguments and updates the information associated with this parser accordingly. |
protected void |
removeGlobalArgument(Argument argument)
Removes the provided argument from the set of global arguments handled by this parser. |
void |
setUsageArgument(Argument argument,
java.io.OutputStream outputStream)
Sets the provided argument as one which will automatically trigger the output of full usage information if it is provided on the command line and no further argument validation will be performed. |
void |
setUsageGroupArgument(Argument argument,
java.util.Collection<SubCommand> subCommands)
Sets the provided argument as one which will automatically trigger the output of partial usage information if it is provided on the command line and no further argument validation will be performed. |
boolean |
usageOrVersionDisplayed()
Indicates whether the usage information has been displayed to the end user either by an explicit argument like "-H" or "--help", or by a built-in argument like "-?". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SubCommandArgumentParser(java.lang.String mainClassName, Message toolDescription, boolean longArgumentsCaseSensitive)
mainClassName
- The fully-qualified name of the Java
class that should be invoked to launch
the program with which this argument
parser is associated.toolDescription
- A human-readable description for the
tool, which will be included when
displaying usage information.longArgumentsCaseSensitive
- Indicates whether subcommand and long
argument names should be treated in a
case-sensitive manner.Method Detail |
---|
public java.lang.String getMainClassName()
getMainClassName
in class ArgumentParser
public Message getToolDescription()
getToolDescription
in class ArgumentParser
null
if
none is available.public boolean longArgumentsCaseSensitive()
true
if subcommand names and long argument strings
should be treated in a case-sensitive manner, or
false
if they should not.public java.util.LinkedList<Argument> getGlobalArgumentList()
public boolean hasGlobalArgument(java.lang.String argumentName)
argumentName
- The name for which to make the determination.
true
if a global argument exists with the specified
name, or false
if not.public Argument getGlobalArgument(java.lang.String name)
name
- The name of the global argument to retrieve.
null
if there is no such argument.public java.util.HashMap<java.lang.Character,Argument> getGlobalArgumentsByShortID()
public boolean hasGlobalArgumentWithShortID(java.lang.Character shortID)
shortID
- The short ID character for which to make the
determination.
true
if a global argument exists with the specified
short ID, or false
if not.public Argument getGlobalArgumentForShortID(java.lang.Character shortID)
shortID
- The short identifier for the global argument to retrieve.
null
if there is no such argument.public java.util.HashMap<java.lang.String,Argument> getGlobalArgumentsByLongID()
public boolean hasGlobalArgumentWithLongID(java.lang.String longID)
longID
- The long ID string for which to make the determination.
true
if a global argument exists with the specified
long ID, or false
if not.public Argument getGlobalArgumentForLongID(java.lang.String longID)
longID
- The long identifier for the global argument to retrieve.
null
if there is no such argument.public java.util.SortedMap<java.lang.String,SubCommand> getSubCommands()
public boolean hasSubCommand(java.lang.String name)
name
- The subcommand name for which to make the determination.
true
if this argument parser has a subcommand with
the specified name, or false
if it does not.public SubCommand getSubCommand(java.lang.String name)
name
- The name of the subcommand to retrieve.
null
if no
such subcommand is defined.public SubCommand getSubCommand()
null
if none was selected.public java.lang.String[] getRawArguments()
getRawArguments
in class ArgumentParser
null
if the argument list has not yet been parsed.public void addGlobalArgument(Argument argument) throws ArgumentException
argument
- The argument to be added.
ArgumentException
- If the provided argument conflicts with another
global or subcommand argument that has already
been defined.public void addGlobalArgument(Argument argument, ArgumentGroup group) throws ArgumentException
argument
- The argument to be added.group
- The argument group to which the argument belongs.
ArgumentException
- If the provided argument conflicts with another
global or subcommand argument that has already
been defined.protected void removeGlobalArgument(Argument argument)
argument
- The argument to be removed.public void setUsageArgument(Argument argument, java.io.OutputStream outputStream)
If sub-command groups are defined using the
setUsageGroupArgument(Argument, Collection)
method, then
this usage argument, when specified, will result in usage
information being displayed which does not include information on
sub-commands.
Note that the caller will still need to add this argument to the
parser with the addGlobalArgument(Argument)
method, and
the argument should not be required and should not take a value.
Also, the caller will still need to check for the presence of the
usage argument after calling parseArguments(String[])
to
know that no further processing will be required.
setUsageArgument
in class ArgumentParser
argument
- The argument whose presence should automatically trigger
the display of full usage information.outputStream
- The output stream to which the usage information should
be written.public void setUsageGroupArgument(Argument argument, java.util.Collection<SubCommand> subCommands)
Partial usage information will include a usage synopsis, a summary of each of the sub-commands listed in the provided sub-commands collection, and a summary of the global options.
Note that the caller will still need to add this argument to the
parser with the addGlobalArgument(Argument)
method, and
the argument should not be required and should not take a value.
Also, the caller will still need to check for the presence of the
usage argument after calling parseArguments(String[])
to
know that no further processing will be required.
argument
- The argument whose presence should automatically trigger
the display of partial usage information.subCommands
- The list of sub-commands which should have their usage
displayed.public void parseArguments(java.lang.String[] rawArguments) throws ArgumentException
parseArguments
in class ArgumentParser
rawArguments
- The raw set of arguments to parse.
ArgumentException
- If a problem was encountered while parsing the
provided arguments.public void parseArguments(java.lang.String[] rawArguments, java.lang.String propertiesFile, boolean requirePropertiesFile) throws ArgumentException
parseArguments
in class ArgumentParser
rawArguments
- The set of raw arguments to parse.propertiesFile
- The path to the properties file to use to
obtain default values for unspecified
properties.requirePropertiesFile
- Indicates whether the parsing should fail if
the provided properties file does not exist
or is not accessible.
ArgumentException
- If a problem was encountered while parsing the
provided arguments or interacting with the
properties file.public void parseArguments(java.lang.String[] rawArguments, java.util.Properties argumentProperties) throws ArgumentException
parseArguments
in class ArgumentParser
rawArguments
- The set of raw arguments to parse.argumentProperties
- A set of properties that may be used to provide
default values for arguments not included in
the given raw arguments.
ArgumentException
- If a problem was encountered while parsing the
provided arguments.public void getSubCommandUsage(MessageBuilder buffer, SubCommand subCommand)
buffer
- The buffer to which the usage information should be
appended.subCommand
- The subcommand for which to display the usage
information.public java.lang.String getUsage()
getUsage
in class ArgumentParser
public Message getHelpUsageReference()
public java.util.ArrayList<java.lang.String> getTrailingArguments()
getTrailingArguments
in class ArgumentParser
public boolean usageOrVersionDisplayed()
usageOrVersionDisplayed
in class ArgumentParser
true
if the usage information has been displayed, or
false
if not.public void getUsage(java.io.OutputStream outputStream) throws java.io.IOException
getUsage
in class ArgumentParser
outputStream
- The output stream to which the usage information
should be written.
java.io.IOException
- If a problem occurs while attempting to write the
usage information to the provided output stream.public boolean isUsageArgumentPresent()
isUsageArgumentPresent
in class ArgumentParser
true
if the usage argument was provided and
false
otherwise.public boolean isVersionArgumentPresent()
isVersionArgumentPresent
in class ArgumentParser
true
if the version argument was provided and
false
otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |