Package com.unboundid.util.args
Class Argument
java.lang.Object
com.unboundid.util.args.Argument
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ArgumentListArgument,BooleanArgument,BooleanValueArgument,ControlArgument,DNArgument,DurationArgument,FileArgument,FilterArgument,IntegerArgument,ScopeArgument,StringArgument,TimestampArgument
@NotExtensible
@Mutable
@ThreadSafety(level=NOT_THREADSAFE)
public abstract class Argument
extends Object
implements Serializable
This class defines a generic command line argument, which provides
functionality applicable to all argument types. Subclasses may enforce
additional constraints or provide additional functionality.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new argument with the same generic information as the provided argument.protectedArgument(Character shortIdentifier, String longIdentifier, boolean isRequired, int maxOccurrences, String valuePlaceholder, String description) Creates a new argument with the provided information. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the provided string to the set of short identifiers for this argument.final voidaddLongIdentifier(String s, boolean isHidden) Adds the provided string to the set of short identifiers for this argument.final voidAdds the provided character to the set of short identifiers for this argument.final voidaddShortIdentifier(Character c, boolean isHidden) Adds the provided character to the set of short identifiers for this argument.protected abstract voidaddToCommandLine(List<String> argStrings) Updates the provided list to add any strings that should be included on the command line in order to represent this argument's current state.protected abstract voidAdds the provided value to the set of values for this argument.protected voidappendBasicToStringInfo(StringBuilder buffer) Appends a basic set of information for this argument to the provided buffer in a form suitable for use in thetoStringmethod.final StringRetrieves the name of the argument group to which this argument belongs.abstract ArgumentCreates a copy of this argument that is "clean" and appears as if it has not been used in the course of parsing an argument set.abstract StringRetrieves a concise name of the data type with which this argument is associated.final StringRetrieves the description for this argument.final StringRetrieves a string that may be used to identify this argument.final StringRetrieves the long identifier for this argument.Retrieves the list of all long identifiers, including hidden identifiers, for this argument.getLongIdentifiers(boolean includeHidden) Retrieves the list of long identifiers for this argument.final intRetrieves the maximum number of times that this argument may be provided.final intRetrieves the number of times that this argument was included in the provided set of command line arguments.final CharacterRetrieves the short identifier for this argument.Retrieves the list of all short identifiers, including hidden identifiers, for this argument.getShortIdentifiers(boolean includeHidden) Retrieves the list of short identifiers for this argument.Retrieves a human-readable string with information about any constraints that may be imposed for values of this argument.final StringRetrieves the value placeholder string for this argument.getValueStringRepresentations(boolean useDefault) Retrieves a list containing the string representations of the values for this argument, if any.protected abstract booleanIndicates whether this argument has one or more default values that will be used if it is not provided on the command line.final booleanIndicates whether this argument has a long identifier.final booleanIndicates whether this argument has a short identifier.final booleanisHidden()Indicates whether this argument should be excluded from usage information.final booleanIndicates whether this argument was either included in the provided set of command line arguments or has a default value that can be used instead.final booleanIndicates whether this argument is required to be provided.final booleanIndicates whether values of this argument are considered sensitive.final booleanIndicates whether this argument is intended to be used to trigger the display of usage information.protected voidreset()Resets this argument so that it appears in the same form as before it was used to parse arguments.final voidsetArgumentGroupName(String argumentGroupName) Sets the name of the argument group to which this argument belongs.final voidsetHidden(boolean isHidden) Specifies whether this argument should be excluded from usage information.final voidsetMaxOccurrences(int maxOccurrences) Specifies the maximum number of times that this argument may be provided.final voidsetSensitive(boolean isSensitive) Specifies whether values of this argument are considered sensitive.final voidsetUsageArgument(boolean isUsageArgument) Specifies whether this argument should be considered a usage argument.booleanIndicates whether this argument takes a value.final StringtoString()Retrieves a string representation of this argument.abstract voidtoString(StringBuilder buffer) Appends a string representation of this argument to the provided buffer.
-
Constructor Details
-
Argument
protected Argument(@Nullable Character shortIdentifier, @Nullable String longIdentifier, boolean isRequired, int maxOccurrences, @Nullable String valuePlaceholder, @NotNull String description) throws ArgumentException Creates a new argument with the provided information.- Parameters:
shortIdentifier- The short identifier for this argument. It may not benullif the long identifier isnull.longIdentifier- The long identifier for this argument. It may not benullif the short identifier isnull.isRequired- Indicates whether this argument is required to be provided.maxOccurrences- The maximum number of times this argument may be provided on the command line. A value less than or equal to zero indicates that it may be present any number of times.valuePlaceholder- A placeholder to display in usage information to indicate that a value must be provided. If this isnull, then the argument will not be allowed to take a value. If it is notnull, then the argument will be required to take a value.description- A human-readable description for this argument. It must not benull.- Throws:
ArgumentException- If there is a problem with the definition of this argument.
-
Argument
Creates a new argument with the same generic information as the provided argument. It will not be registered with any argument parser.- Parameters:
source- The argument to use as the source for this argument.
-
-
Method Details
-
hasShortIdentifier
Indicates whether this argument has a short identifier.- Returns:
trueif it has a short identifier, orfalseif not.
-
getShortIdentifier
Retrieves the short identifier for this argument. If there is more than one, then the first will be returned.- Returns:
- The short identifier for this argument, or
nullif none is defined.
-
getShortIdentifiers
Retrieves the list of all short identifiers, including hidden identifiers, for this argument.- Returns:
- The list of all short identifiers for this argument, or an empty list if there are no short identifiers.
-
getShortIdentifiers
Retrieves the list of short identifiers for this argument.- Parameters:
includeHidden- Indicates whether to include hidden identifiers in the list that is returned.- Returns:
- The list of short identifiers for this argument, or an empty list if there are none.
-
addShortIdentifier
Adds the provided character to the set of short identifiers for this argument. It will not be hidden. Note that this must be called before this argument is registered with the argument parser.- Parameters:
c- The character to add to the set of short identifiers for this argument. It must not benull.- Throws:
ArgumentException- If this argument is already registered with the argument parser.
-
addShortIdentifier
public final void addShortIdentifier(@NotNull Character c, boolean isHidden) throws ArgumentException Adds the provided character to the set of short identifiers for this argument. Note that this must be called before this argument is registered with the argument parser.- Parameters:
c- The character to add to the set of short identifiers for this argument. It must not benull.isHidden- Indicates whether the provided identifier should be hidden. If this istrue, then the identifier can be used to target this argument on the command line, but it will not be included in usage information.- Throws:
ArgumentException- If this argument is already registered with the argument parser.
-
hasLongIdentifier
Indicates whether this argument has a long identifier.- Returns:
trueif it has a long identifier, orfalseif not.
-
getLongIdentifier
Retrieves the long identifier for this argument. If it has multiple long identifiers, then the first will be returned.- Returns:
- The long identifier for this argument, or
nullif none is defined.
-
getLongIdentifiers
Retrieves the list of all long identifiers, including hidden identifiers, for this argument.- Returns:
- The list of all long identifiers for this argument, or an empty list if there are no long identifiers.
-
getLongIdentifiers
Retrieves the list of long identifiers for this argument.- Parameters:
includeHidden- Indicates whether to include hidden identifiers in the list that is returned.- Returns:
- The long identifier for this argument, or an empty list if there are none.
-
addLongIdentifier
Adds the provided string to the set of short identifiers for this argument. It will not be hidden. Note that this must be called before this argument is registered with the argument parser.- Parameters:
s- The string to add to the set of short identifiers for this argument. It must not benull.- Throws:
ArgumentException- If this argument is already registered with the argument parser.
-
addLongIdentifier
Adds the provided string to the set of short identifiers for this argument. Note that this must be called before this argument is registered with the argument parser.- Parameters:
s- The string to add to the set of short identifiers for this argument. It must not benull.isHidden- Indicates whether the provided identifier should be hidden. If this istrue, then the identifier can be used to target this argument on the command line, but it will not be included in usage information.- Throws:
ArgumentException- If this argument is already registered with the argument parser.
-
getIdentifierString
Retrieves a string that may be used to identify this argument. If a long identifier is defined, then the value returned will be two dashes followed by that string. Otherwise, the value returned will be a single dash followed by the short identifier.- Returns:
- A string that may be used to identify this argument.
-
isRequired
Indicates whether this argument is required to be provided.- Returns:
trueif this argument is required to be provided, orfalseif not.
-
getMaxOccurrences
Retrieves the maximum number of times that this argument may be provided.- Returns:
- The maximum number of times that this argument may be provided.
-
setMaxOccurrences
Specifies the maximum number of times that this argument may be provided.- Parameters:
maxOccurrences- The maximum number of times that this argument may be provided. A value less than or equal to zero indicates that there should be no limit on the maximum number of occurrences.
-
takesValue
Indicates whether this argument takes a value.- Returns:
trueif this argument takes a value, orfalseif not.
-
getValuePlaceholder
Retrieves the value placeholder string for this argument.- Returns:
- The value placeholder string for this argument, or
nullif it does not take a value.
-
getValueStringRepresentations
Retrieves a list containing the string representations of the values for this argument, if any. The list returned does not necessarily need to include values that will be acceptable to the argument, but it should imply what the values are (e.g., in the case of a boolean argument that doesn't take a value, it may be the string "true" or "false" even if those values are not acceptable to the argument itself).- Parameters:
useDefault- Indicates whether to use any configured default value if the argument doesn't have a user-specified value.- Returns:
- A string representation of the value for this argument, or an empty list if the argument does not have a value.
-
getDescription
Retrieves the description for this argument.- Returns:
- The description for this argument.
-
getArgumentGroupName
Retrieves the name of the argument group to which this argument belongs.- Returns:
- The name of the argument group to which this argument belongs, or
nullif this argument has not been assigned to any group.
-
setArgumentGroupName
Sets the name of the argument group to which this argument belongs. If a tool updates arguments to specify an argument group for some or all of the arguments, then the usage information will have the arguments listed together in their respective groups. Note that usage arguments should generally not be assigned to an argument group.- Parameters:
argumentGroupName- The argument group name for this argument. It may benullif this argument should not be assigned to any particular group.
-
isHidden
Indicates whether this argument should be excluded from usage information.- Returns:
trueif this argument should be excluded from usage information, orfalseif not.
-
setHidden
Specifies whether this argument should be excluded from usage information.- Parameters:
isHidden- Specifies whether this argument should be excluded from usage information.
-
isUsageArgument
Indicates whether this argument is intended to be used to trigger the display of usage information. If a usage argument is provided on the command line, then the argument parser will not complain about missing required arguments or unresolved dependencies.- Returns:
trueif this argument is a usage argument, orfalseif not.
-
setUsageArgument
Specifies whether this argument should be considered a usage argument.- Parameters:
isUsageArgument- Specifies whether this argument should be considered a usage argument.
-
isPresent
Indicates whether this argument was either included in the provided set of command line arguments or has a default value that can be used instead. This method should not be called until after the argument parser has processed the provided set of arguments.- Returns:
trueif this argument was included in the provided set of command line arguments, orfalseif not.
-
getNumOccurrences
Retrieves the number of times that this argument was included in the provided set of command line arguments. This method should not be called until after the argument parser has processed the provided set of arguments.- Returns:
- The number of times that this argument was included in the provided set of command line arguments.
-
addValue
Adds the provided value to the set of values for this argument. This method should only be called by the argument parser.- Parameters:
valueString- The string representation of the value.- Throws:
ArgumentException- If the provided value is not acceptable, if this argument does not accept values, or if this argument already has the maximum allowed number of values.
-
hasDefaultValue
Indicates whether this argument has one or more default values that will be used if it is not provided on the command line.- Returns:
trueif this argument has one or more default values, orfalseif not.
-
isSensitive
Indicates whether values of this argument are considered sensitive. Argument values that are considered sensitive will be obscured in places where they may be shown.- Returns:
trueif values of this argument are considered sensitive, orfalseif not.
-
setSensitive
Specifies whether values of this argument are considered sensitive. Argument values that are considered sensitive will be obscured in places where they may be shown.- Parameters:
isSensitive- Indicates whether values of this argument are considered sensitive.
-
getDataTypeName
Retrieves a concise name of the data type with which this argument is associated.- Returns:
- A concise name of the data type with which this argument is associated.
-
getValueConstraints
Retrieves a human-readable string with information about any constraints that may be imposed for values of this argument.- Returns:
- A human-readable string with information about any constraints
that may be imposed for values of this argument, or
nullif there are none.
-
reset
Resets this argument so that it appears in the same form as before it was used to parse arguments. Subclasses that override this method must callsuper.reset()to ensure that all necessary reset processing is performed. -
getCleanCopy
Creates a copy of this argument that is "clean" and appears as if it has not been used in the course of parsing an argument set. The new argument will have all of the same identifiers and constraints as this parser.- Returns:
- The "clean" copy of this argument.
-
addToCommandLine
Updates the provided list to add any strings that should be included on the command line in order to represent this argument's current state.- Parameters:
argStrings- The list to update with the string representation of the command-line arguments.
-
toString
Retrieves a string representation of this argument. -
toString
Appends a string representation of this argument to the provided buffer.- Parameters:
buffer- The buffer to which the information should be appended.
-
appendBasicToStringInfo
Appends a basic set of information for this argument to the provided buffer in a form suitable for use in thetoStringmethod.- Parameters:
buffer- The buffer to which information should be appended.
-