ArgumentParser.java revision 27d398c0bcca6adaf643fa3f6fd02ed67ff4adf1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions copyright 2012-2015 ForgeRock AS.
*/
/**
* This class defines a utility that can be used to deal with command-line
* arguments for applications in a CLIP-compliant manner using either short
* one-character or longer word-based arguments. It is also integrated with the
* Directory Server message catalog so that it can display messages in an
* internationalizable format, can automatically generate usage information,
* can detect conflicts between arguments, and can interact with a properties
* file to obtain default values for arguments there if they are not specified
* on the command-line.
*/
public class ArgumentParser {
/**
* The name of the OpenDJ configuration direction in the user home
* directory.
*/
/** The default properties file name. */
/** The default properties file extension. */
/** The name of a command-line script used to launch a tool. */
/** The legacy name of a command-line script used to launch a tool. */
/** The argument that will be used to indicate the file properties. */
private StringArgument filePropertiesPathArgument;
/**
* The argument that will be used to indicate that we'll not look for
* default properties file.
*/
private BooleanArgument noPropertiesFileArgument;
/**
* The argument that will be used to trigger the display of usage
* information.
*/
private Argument usageArgument;
/**
* The argument that will be used to trigger the display of the OpenDJ
* version.
*/
private Argument versionArgument;
/** The set of unnamed trailing arguments that were provided for this parser. */
/**
* Indicates whether this parser will allow additional unnamed arguments at
* the end of the list.
*/
private final boolean allowsTrailingArguments;
/**
* Indicates whether long arguments should be treated in a case-sensitive
* manner.
*/
private final boolean longArgumentsCaseSensitive;
/** Indicates whether the usage or version information has been displayed. */
private boolean usageOrVersionDisplayed;
/** Indicates whether the version argument was provided. */
private boolean versionPresent;
/** The handler to call to print the product version. */
private VersionHandler versionHandler;
/** The set of arguments defined for this parser, referenced by short ID. */
/** The set of arguments defined for this parser, referenced by long ID. */
/** The set of arguments defined for this parser, referenced by argument name. */
/** The total set of arguments defined for this parser. */
/** The maximum number of unnamed trailing arguments that may be provided. */
private final int maxTrailingArguments;
/** The minimum number of unnamed trailing arguments that may be provided. */
private final int minTrailingArguments;
/** The output stream to which usage information should be printed. */
/**
* The fully-qualified name of the Java class that should be invoked to
* launch the program with which this argument parser is associated.
*/
private final String mainClassName;
/**
* A human-readable description for the tool, which will be included when
* displaying usage information.
*/
private final LocalizableMessage toolDescription;
/**
* The display name that will be used for the trailing arguments in the
* usage information.
*/
private final String trailingArgsDisplayName;
/** The raw set of command-line arguments that were provided. */
private String[] rawArguments;
/** Set of argument groups. */
/**
* Group for arguments that have not been explicitly grouped. These will
* appear at the top of the usage statement without a header.
*/
/**
* Group for arguments that are related to connection through LDAP. This
* includes options like the bind DN, the port, etc.
*/
/**
* properties file, no-prompt etc. These will appear toward the bottom of
* the usage statement.
*/
/**
* Group for arguments that are general like help, version etc. These will
* appear at the end of the usage statement.
*/
/**
* Creates a new instance of this argument parser with no arguments. Unnamed
* trailing arguments will not be allowed.
*
* @param mainClassName
* The fully-qualified name of the Java class that should be
* invoked to launch the program with which this argument parser
* is associated.
* @param toolDescription
* A human-readable description for the tool, which will be
* included when displaying usage information.
* @param longArgumentsCaseSensitive
* Indicates whether long arguments should be treated in a
* case-sensitive manner.
*/
final boolean longArgumentsCaseSensitive) {
this.mainClassName = mainClassName;
this.toolDescription = toolDescription;
allowsTrailingArguments = false;
maxTrailingArguments = 0;
minTrailingArguments = 0;
initGroups();
}
/**
* Creates a new instance of this argument parser with no arguments that may
* or may not be allowed to have unnamed trailing arguments.
*
* @param mainClassName
* The fully-qualified name of the Java class that should be
* invoked to launch the program with which this argument parser
* is associated.
* @param toolDescription
* A human-readable description for the tool, which will be
* included when displaying usage information.
* @param longArgumentsCaseSensitive
* Indicates whether long arguments should be treated in a
* case-sensitive manner.
* @param allowsTrailingArguments
* Indicates whether this parser allows unnamed trailing
* arguments to be provided.
* @param minTrailingArguments
* The minimum number of unnamed trailing arguments that must be
* provided. A value less than or equal to zero indicates that no
* minimum will be enforced.
* @param maxTrailingArguments
* The maximum number of unnamed trailing arguments that may be
* provided. A value less than or equal to zero indicates that no
* maximum will be enforced.
* @param trailingArgsDisplayName
* The display name that should be used as a placeholder for
* unnamed trailing arguments in the generated usage information.
*/
final boolean longArgumentsCaseSensitive, final boolean allowsTrailingArguments,
final int minTrailingArguments, final int maxTrailingArguments,
final String trailingArgsDisplayName) {
this.mainClassName = mainClassName;
this.toolDescription = toolDescription;
initGroups();
}
/**
* Adds the provided argument to the set of arguments handled by this
* parser.
*
* @param argument
* The argument to be added.
* @throws ArgumentException
* If the provided argument conflicts with another argument that
* has already been defined.
*/
}
/**
* Adds the provided argument to the set of arguments handled by this
* parser.
*
* @param argument
* The argument to be added.
* @param group
* The argument group to which the argument belongs.
* @throws ArgumentException
* If the provided argument conflicts with another argument that
* has already been defined.
*/
throw new ArgumentException(
}
// JNR: what is the requirement for the following code?
if (versionArgument != null
// Update the version argument to not display its short identifier.
try {
versionArgument = getVersionArgument(false);
// JNR: why not call addGeneralArgument(versionArgument) here?
} catch (final ArgumentException e) {
// ignore
}
}
if (!longArgumentsCaseSensitive) {
}
}
}
}
}
}
}
private BooleanArgument getVersionArgument(final boolean displayShortIdentifier) throws ArgumentException {
return new BooleanArgument(OPTION_LONG_PRODUCT_VERSION, displayShortIdentifier ? OPTION_SHORT_PRODUCT_VERSION
}
/**
* Adds the provided argument to the set of arguments handled by this parser
* and puts the argument in the default group.
*
* @param argument
* The argument to be added.
* @throws ArgumentException
* If the provided argument conflicts with another argument that
* has already been defined.
*/
}
/**
* Adds the provided argument to the set of arguments handled by this parser
* and puts the argument in the LDAP connection group.
*
* @param argument
* The argument to be added.
* @throws ArgumentException
* If the provided argument conflicts with another argument that
* has already been defined.
*/
}
/**
* Indicates whether this parser will allow unnamed trailing arguments.
* These will be arguments at the end of the list that are not preceded by
* either a long or short identifier and will need to be manually parsed by
* the application using this parser. Note that once an unnamed trailing
* argument has been identified, all remaining arguments will be classified
* as such.
*
* @return <CODE>true</CODE> if this parser allows unnamed trailing
* arguments, or <CODE>false</CODE> if it does not.
*/
boolean allowsTrailingArguments() {
return allowsTrailingArguments;
}
/**
* Check if we have a properties file.
*
* @return The properties found in the properties file or null.
* @throws ArgumentException
* If a problem was encountered while parsing the provided
* arguments.
*/
// We don't look for properties file.
return null;
}
// Check if we have a properties file argument
if (filePropertiesPathArgument == null) {
return null;
}
// check if the properties file argument has been set. If not
// look for default location.
if (filePropertiesPathArgument.isPresent()) {
} else {
// Check in "user home"/.opendj directory
}
// We don't have a properties file location
if (propertiesFilePath == null) {
return null;
}
// We have a location for the properties file.
try {
final Properties p = new Properties();
// Property name form <script name>.<property name> has the
// precedence to <property name>
if (scriptName != null) {
continue;
}
}
}
} catch (final Exception e) {
final LocalizableMessage message =
throw new ArgumentException(message, e);
}
return argumentProperties;
}
/**
* Retrieves the argument with the specified name.
*
* @param name
* The name of the argument to retrieve.
* @return The argument with the specified name, or <CODE>null</CODE> if
* there is no such argument.
*/
}
/**
* Retrieves the argument with the specified long identifier.
*
* @param longID
* The long identifier of the argument to retrieve.
* @return The argument with the specified long identifier, or
* <CODE>null</CODE> if there is no such argument.
*/
}
/**
* Retrieves the argument with the specified short identifier.
*
* @param shortID
* The short ID for the argument to retrieve.
* @return The argument with the specified short identifier, or
* <CODE>null</CODE> if there is no such argument.
*/
}
/**
* Retrieves the list of all arguments that have been defined for this
* argument parser.
*
* @return The list of all arguments that have been defined for this
* argument parser.
*/
return argumentList;
}
/**
* Retrieves the set of arguments mapped by the long identifier that may be
* used to reference them. Note that arguments that do not have a long
* identifier will not be present in this list.
*
* @return The set of arguments mapped by the long identifier that may be
* used to reference them.
*/
return longIDMap;
}
/**
* Retrieves the set of arguments mapped by the short identifier that may be
* used to reference them. Note that arguments that do not have a short
* identifier will not be present in this list.
*
* @return The set of arguments mapped by the short identifier that may be
* used to reference them.
*/
return shortIDMap;
}
/**
* Retrieves the fully-qualified name of the Java class that should be
* invoked to launch the program with which this argument parser is
* associated.
*
* @return The fully-qualified name of the Java class that should be invoked
* to launch the program with which this argument parser is
* associated.
*/
return mainClassName;
}
/**
* Retrieves the maximum number of unnamed trailing arguments that may be
* provided.
*
* @return The maximum number of unnamed trailing arguments that may be
* provided, or a value less than or equal to zero if no maximum
* will be enforced.
*/
int getMaxTrailingArguments() {
return maxTrailingArguments;
}
/**
* Retrieves the minimum number of unnamed trailing arguments that must be
* provided.
*
* @return The minimum number of unnamed trailing arguments that must be
* provided, or a value less than or equal to zero if no minimum
* will be enforced.
*/
int getMinTrailingArguments() {
return minTrailingArguments;
}
/**
* Retrieves the raw set of arguments that were provided.
*
* @return The raw set of arguments that were provided, or <CODE>null</CODE>
* if the argument list has not yet been parsed.
*/
String[] getRawArguments() {
return rawArguments;
}
/**
* Given an argument, returns an appropriate group. Arguments may be part of
* one of the special groups or the default group.
*
* @param argument
* for which a group is requested
* @return argument group appropriate for <code>argument</code>
*/
if (isInputOutputArgument(argument)) {
return ioArgGroup;
} else if (isGeneralArgument(argument)) {
return generalArgGroup;
} else if (isLdapConnectionArgument(argument)) {
return ldapArgGroup;
} else {
return defaultArgGroup;
}
}
/**
* Retrieves a human-readable description for this tool, which should be
* included at the top of the command-line usage information.
*
* @return A human-readable description for this tool, or {@code null} if
* none is available.
*/
return toolDescription;
}
/**
* A short description for this tool, suitable in a man page summary line.
*/
private LocalizableMessage shortToolDescription;
/**
* Gets a short description for this tool, suitable in a man page summary line.
*
* @return A short description for this tool,
* suitable in a man page summary line,
* or LocalizableMessage.EMPTY if there is no short description.
*/
}
/**
* Sets a short description for this tool, suitable in a man page summary line.
*
* @param shortDescription The short description for this tool,
* suitable in a man page summary line.
*/
this.shortToolDescription = shortDescription;
}
/**
* A supplement to the description for this tool
* intended for use in generated reference documentation.
*/
/**
* Retrieves a supplement to the description for this tool,
* intended for use in generated reference documentation.
*
* @return A supplement to the description for this tool
* intended for use in generated reference documentation,
* or LocalizableMessage.EMPTY if there is no supplement.
*/
return docToolDescriptionSupplement != null ? docToolDescriptionSupplement : LocalizableMessage.EMPTY;
}
/**
* Sets a supplement to the description for this tool,
* intended for use in generated reference documentation.
*
* @param docToolDescriptionSupplement The supplement to the description for this tool
* intended for use in generated reference documentation.
*/
public void setDocToolDescriptionSupplement(final LocalizableMessage docToolDescriptionSupplement) {
}
/**
* Retrieves the set of unnamed trailing arguments that were provided on the
* command line.
*
* @return The set of unnamed trailing arguments that were provided on the
* command line.
*/
return trailingArguments;
}
/**
* Retrieves a string containing usage information based on the defined
* arguments.
*
* @return A string containing usage information based on the defined
* arguments.
*/
usageOrVersionDisplayed = true;
} else {
}
}
/**
* Appends a generated DocBook XML RefEntry (man page) to the StringBuilder.
*
* @param sb Append the RefEntry element to this.
*/
if (scriptName == null) {
throw new RuntimeException("The script name should have been set via the environment property '"
+ PROPERTY_SCRIPT_NAME + "'.");
}
// Model for a FreeMarker template.
if (allowsTrailingArguments) {
if (trailingArgsDisplayName != null) {
} else {
}
}
// If there is a supplement to the description for this utility,
// then it is already DocBook XML, so use it as is.
if (!argumentList.isEmpty()) {
for (Argument a : argumentList) {
// If there is a supplement to the description for this argument,
// then it is already DocBook XML, so use it as is.
}
}
}
/**
* Writes message to the usage output stream.
*
* @param message the message to write
*/
try {
} catch (final Exception e) {
logger.traceException(e);
}
}
/**
* Appends usage information based on the defined arguments to the provided
* buffer.
*
* @param buffer
* The buffer to which the usage information should be appended.
*/
if (allowsTrailingArguments) {
if (trailingArgsDisplayName != null) {
} else {
}
}
}
final boolean printHeaders = printUsageGroupHeaders();
// Print the groups description if any
}
}
/** {@inheritDoc} */
if (res != 0) {
return res;
}
// Lowercase options first then uppercase.
}
}
return o1.getLongIdentifier();
}
});
// If this argument is hidden, then skip it.
if (a.isHidden()) {
continue;
}
// Help argument should be printed at the end
if (isUsageArgument(a)) {
helpArgument = a;
continue;
}
printArgumentUsage(a, buffer);
}
}
if (helpArgument != null) {
} else {
}
}
/**
* Returns the script name or a Java equivalent command-line string.
*
* @return the script name or a Java equivalent command-line string
*/
return scriptName;
}
return "java " + getMainClassName();
}
/**
* Returns the script name as a {@link LocalizableMessage}.
*
* @return the script name as a {@link LocalizableMessage}
*/
}
}
/**
* Returns the script name if set.
*
* @return the script name, or {@code null} if not set
*/
String getScriptName() {
return scriptName;
}
return legacyScriptName;
}
return null;
}
/**
* Returns the usage argument.
*
* @return the usageArgument
*/
return usageArgument;
}
/**
* Returns whether the provided argument is the usage argument.
*
* @param a the argument to test
* @return true if the provided argument is the usage argument, false otherwise
*/
boolean isUsageArgument(final Argument a) {
}
/**
* Retrieves a message containing usage information based on the defined
* arguments.
*
* @return A string containing usage information based on the defined
* arguments.
*/
public LocalizableMessage getUsageMessage() {
// TODO: rework getUsage(OutputStream) to work with messages framework
}
/**
* Returns the version handler.
*
* @return the version handler
*/
return versionHandler;
}
/** Prints the version. */
void printVersion() {
versionPresent = true;
usageOrVersionDisplayed = true;
}
/**
* Returns whether the usage argument was provided or not. This method
* should be called after a call to parseArguments.
*
* @return <CODE>true</CODE> if the usage argument was provided and
* <CODE>false</CODE> otherwise.
*/
public boolean isUsageArgumentPresent() {
}
/**
* Returns whether the version argument was provided or not. This method
* should be called after a call to parseArguments.
*
* @return <CODE>true</CODE> if the version argument was provided and
* <CODE>false</CODE> otherwise.
*/
public boolean isVersionArgumentPresent() {
return versionPresent;
}
/**
* Indicates whether subcommand names and long argument strings should be treated in a case-sensitive manner.
*
* @return <CODE>true</CODE> if subcommand names and long argument strings should be treated in a case-sensitive
* manner, or <CODE>false</CODE> if they should not.
*/
boolean longArgumentsCaseSensitive() {
return longArgumentsCaseSensitive;
}
/**
* Parses the provided set of arguments and updates the information
* associated with this parser accordingly.
*
* @param rawArguments
* The raw set of arguments to parse.
* @throws ArgumentException
* If a problem was encountered while parsing the provided
* arguments.
*/
}
/**
* Parses the provided set of arguments and updates the information
* associated with this parser accordingly. Default values for unspecified
* arguments may be read from the specified properties if any are provided.
*
* @param rawArguments
* The set of raw arguments to parse.
* @param argumentProperties
* A set of properties that may be used to provide default values
* for arguments not included in the given raw arguments.
* @throws ArgumentException
* If a problem was encountered while parsing the provided
* arguments.
*/
throws ArgumentException {
this.rawArguments = rawArguments;
boolean inTrailingArgs = false;
for (int i = 0; i < numArguments; i++) {
if (inTrailingArgs) {
final LocalizableMessage message =
throw new ArgumentException(message);
}
continue;
}
// This is a special indicator that we have reached the end of
// the named arguments and that everything that follows after
// this should be considered trailing arguments.
inTrailingArgs = true;
// This indicates that we are using the long name to reference
// the argument. It may be in any of the following forms:
// --name
// --name value
// --name=value
if (equalPos < 0) {
// This is fine. The value is not part of the argument name
// token.
} else if (equalPos == 0) {
// The argument starts with "--=", which is not acceptable.
} else {
// The argument is in the form --name=value, so parse them
// both out.
}
// If we're not case-sensitive, then convert the name to
// lowercase.
if (!longArgumentsCaseSensitive) {
}
// Get the argument with the specified name.
if (a == null) {
// "--help" will always be interpreted as requesting
// usage information.
return;
// "--version" will always be interpreted as requesting version information.
printVersion();
return;
} else {
// There is no such argument registered.
throw new ArgumentException(
}
} else {
a.setPresent(true);
// If this is the usage argument, then immediately stop and
// print usage information.
if (isUsageArgument(a)) {
return;
}
}
// See if the argument takes a value. If so, then make sure one
// was provided. If not, then make sure none was provided.
if (a.needsValue()) {
if ((i + 1) == numArguments) {
throw new ArgumentException(
}
argValue = rawArguments[++i];
}
throw new ArgumentException(
}
// If the argument already has a value, then make sure it is
// acceptable to have more than one.
if (a.hasValue() && !a.isMultiValued()) {
}
throw new ArgumentException(
}
// This indicates that we are using the 1-character name to
// reference the argument. It may be in any of the following
// forms:
// -n
// -nvalue
// -n value
}
} else {
}
// Get the argument with the specified short ID.
if (a == null) {
if (argCharacter == '?') {
return;
printVersion();
return;
} else {
// There is no such argument registered.
}
} else {
a.setPresent(true);
// If this is the usage argument, then immediately stop and
// print usage information.
if (isUsageArgument(a)) {
return;
}
}
// See if the argument takes a value. If so, then make sure one
// was provided. If not, then make sure none was provided.
if (a.needsValue()) {
if ((i + 1) == numArguments) {
throw new ArgumentException(
}
argValue = rawArguments[++i];
}
}
// If the argument already has a value, then make sure it is
// acceptable to have more than one.
if (a.hasValue() && !a.isMultiValued()) {
}
// If we've gotten here, then it means that we're in a scenario like
// "-abc" where "a" is a valid argument that doesn't take a value.
// However, this could still be valid if all remaining characters
// in the value are also valid argument characters that don't take values.
for (int j = 0; j < valueLength; j++) {
if (b == null) {
// There is no such argument registered.
throw new ArgumentException(
} else if (b.needsValue()) {
// This means we're in a scenario like "-abc"
// where b is a valid argument that takes a value.
// We don't support that.
throw new ArgumentException(
} else {
b.setPresent(true);
// If this is the usage argument,
// then immediately stop and print usage information.
if (isUsageArgument(b)) {
return;
}
}
}
}
} else if (allowsTrailingArguments) {
// It doesn't start with a dash, so it must be a trailing
// argument if that is acceptable.
inTrailingArgs = true;
} else {
// It doesn't start with a dash and we don't allow trailing
// arguments, so this is illegal.
}
}
// If we allow trailing arguments and there is a minimum number,
// then make sure at least that many were provided.
&& minTrailingArguments > 0
}
// If we don't have the argumentProperties, try to load a properties file
if (argumentProperties == null) {
}
// Iterate through all of the arguments.
// For any that were not provided on the command line,
// see if there is an alternate default that can be used.
// For cases where there is not, see that argument is required.
}
/**
* Parses the provided set of arguments and updates the information
* associated with this parser accordingly. Default values for unspecified
* arguments may be read from the specified properties file.
*
* @param rawArguments
* The set of raw arguments to parse.
* @param propertiesFile
* The path to the properties file to use to obtain default
* values for unspecified properties.
* @param requirePropertiesFile
* Indicates whether the parsing should fail if the provided
* properties file does not exist or is not accessible.
* @throws ArgumentException
* If a problem was encountered while parsing the provided
* arguments or interacting with the properties file.
*/
final boolean requirePropertiesFile) throws ArgumentException {
this.rawArguments = rawArguments;
try {
final Properties p = new Properties();
argumentProperties = p;
} catch (final Exception e) {
if (requirePropertiesFile) {
final LocalizableMessage message =
throw new ArgumentException(message, e);
}
} finally {
}
}
/**
* Indicates whether or not argument group description headers should be
* printed.
*
* @return boolean where true means print the descriptions
*/
boolean printUsageGroupHeaders() {
// If there is only a single group then we won't print them.
int groupsContainingArgs = 0;
if (argGroup.containsNonHiddenArguments()) {
}
}
return groupsContainingArgs > 1;
}
/**
* Sets the usage group description for the default argument group.
*
* @param description
* for the default group
*/
}
/**
* Sets the provided argument which will be used to identify the file
* properties.
*
* @param argument
* The argument which will be used to identify the file
* properties.
*/
}
/**
* Sets the usage group description for the general argument group.
*
* @param description
* for the general group
*/
}
/**
*
* @param description
*/
}
/**
* Sets the usage group description for the LDAP argument group.
*
* @param description
* for the LDAP group
*/
}
/**
* Sets the provided argument which will be used to identify the file
* properties.
*
* @param argument
* The argument which will be used to indicate if we have to look
* for properties file.
*/
}
/**
* Sets the raw set of arguments.
*
* @param rawArguments the raw set of arguments to set
*/
this.rawArguments = rawArguments;
}
/**
* Sets the provided argument as one which will automatically trigger the
* output of usage information if it is provided on the command line and no
* further argument validation will be performed. Note that the caller will
* still need to add this argument to the parser with the
* <CODE>addArgument</CODE> 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
* <CODE>parseArguments</CODE> to know that no further processing will be
* required.
*
* @param argument
* The argument whose presence should automatically trigger the
* display of usage information.
*/
}
/**
* Sets the provided argument as one which will automatically trigger the
* output of usage information if it is provided on the command line and no
* further argument validation will be performed. Note that the caller will
* still need to add this argument to the parser with the
* <CODE>addArgument</CODE> 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
* <CODE>parseArguments</CODE> to know that no further processing will be
* required.
*
* @param argument
* The argument whose presence should automatically trigger the
* display of usage information.
* @param outputStream
* The output stream to which the usage information should be
* written.
*/
}
/**
* Sets whether the usage or version displayed.
*
* @param usageOrVersionDisplayed the usageOrVersionDisplayed to set
*/
public void setUsageOrVersionDisplayed(boolean usageOrVersionDisplayed) {
}
/**
* Sets the version handler which will be used to display the product version.
*
* @param handler
* The version handler.
*/
}
/**
* Indicates whether the version or 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 "-?".
*
* @return {@code true} if the usage information has been displayed, or
* {@code false} if not.
*/
public boolean usageOrVersionDisplayed() {
return usageOrVersionDisplayed;
}
/**
* Get the absolute path of the properties file.
*
* @param directory
* The location in which we should look for properties file
* @return The absolute path of the properties file or null
*/
// Look for the tools properties file
final File f =
return f.getAbsolutePath();
}
return null;
}
private void initGroups() {
try {
versionArgument = getVersionArgument(true);
// JNR: why not call addGeneralArgument(versionArgument) here?
} catch (final ArgumentException e) {
// ignore
}
}
}
return false;
}
}
return false;
}
}
return false;
}
/**
* Appends argument usage information to the provided buffer.
*
* @param a
* The argument to handle.
* @param buffer
* The buffer to which the usage information should be appended.
*/
// Write one or more lines with the description of the argument.
// We will indent the description five characters and try our best to wrap
// at or before column 79 so it will be friendly to 80-column displays.
}
}
/**
* Appends a line with the short and/or long identifiers that may be used for the argument to the provided string
* builder.
*
* @param a the argument for which to print a line
* @param buffer the string builder where to append the line
*/
if (isUsageArgument(a)) {
}
}
if (a.needsValue()) {
}
if (lineLength > MAX_LINE_WIDTH) {
}
}
if (isUsageArgument(a)) {
}
if (a.needsValue()) {
}
}
}
throws ArgumentException {
if (!a.isPresent()
// See if there is a value in the properties that can be used
boolean addValue = !(a instanceof BooleanArgument)
if (addValue) {
if (a.needsValue()) {
a.setPresent(true);
}
a.setValueSetByProperty(true);
}
}
}
if (!a.isPresent() && a.needsValue()) {
// See if the argument defines a default.
if (a.getDefaultValue() != null) {
a.addValue(a.getDefaultValue());
}
// If there is still no value and the argument is required, then that's a problem.
if (!a.hasValue() && a.isRequired()) {
}
}
}
}
/**
* Get the password which has to be used for the command without prompting the user. If no password was specified,
* return null.
*
* @param clearArg
* The password StringArgument argument.
* @param fileArg
* The password FileBased argument.
* @return The password stored into the specified file on by the command line argument, or null it if not specified.
*/
}
return null;
}
}