From 184ed890c828220c114f60ee165ce2230ada3d7c Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Tue, 15 May 2007 08:10:13 +0000
Subject: [PATCH] issue 1430 fix (all utilities should provide as standard option -V/--version) to specify the LDAP protocol version number, we should use now -V/--ldapVersion to get the 'product' version --version
---
opends/src/server/org/opends/server/util/args/ArgumentParser.java | 69 ++++++++++++++++++++++++++++------
1 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index 9608bd2..5428335 100644
--- a/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -36,11 +36,14 @@
import java.util.LinkedList;
import java.util.Properties;
+import org.opends.server.core.DirectoryServer;
+
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.server.messages.UtilityMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
-
+import static org.opends.server.tools.ToolConstants.*;
+import static org.opends.server.messages.ToolMessages.*;
/**
@@ -69,8 +72,8 @@
// manner.
private boolean longArgumentsCaseSensitive;
- // Indicates whether the usage information has been displayed.
- private boolean usageDisplayed;
+ // Indicates whether the usage or version information has been displayed.
+ private boolean usageOrVersionDisplayed;
// The set of arguments defined for this parser, referenced by short ID.
private HashMap<Character,Argument> shortIDMap;
@@ -136,7 +139,7 @@
shortIDMap = new HashMap<Character,Argument>();
longIDMap = new HashMap<String,Argument>();
allowsTrailingArguments = false;
- usageDisplayed = false;
+ usageOrVersionDisplayed = false;
trailingArgsDisplayName = null;
maxTrailingArguments = 0;
minTrailingArguments = 0;
@@ -198,7 +201,7 @@
shortIDMap = new HashMap<Character,Argument>();
longIDMap = new HashMap<String,Argument>();
trailingArguments = new ArrayList<String>();
- usageDisplayed = false;
+ usageOrVersionDisplayed = false;
rawArguments = null;
usageArgument = null;
usageOutputStream = System.out;
@@ -663,6 +666,19 @@
return;
}
else
+ if (argName.equals(OPTION_LONG_PRODUCT_VERSION))
+ {
+ // "--version" will always be interpreted as requesting version
+ // information.
+ usageOrVersionDisplayed = true;
+ try
+ {
+ DirectoryServer.printVersion(usageOutputStream);
+ } catch (Exception e) {}
+
+ return;
+ }
+ else
{
// There is no such argument registered.
int msgID = MSGID_ARGPARSER_NO_ARGUMENT_WITH_LONG_ID;
@@ -775,6 +791,21 @@
return;
}
else
+ if ( (argCharacter == OPTION_SHORT_PRODUCT_VERSION)
+ &&
+ ( ! shortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION)))
+ {
+ // "-V" will always be interpreted as requesting
+ // version information except if it's already defined (e.g in
+ // lpda tools).
+ usageOrVersionDisplayed = true ;
+ try
+ {
+ DirectoryServer.printVersion(usageOutputStream);
+ } catch (Exception e) {}
+ return;
+ }
+ else
{
// There is no such argument registered.
int msgID = MSGID_ARGPARSER_NO_ARGUMENT_WITH_SHORT_ID;
@@ -970,7 +1001,7 @@
*/
public void getUsage(StringBuilder buffer)
{
- usageDisplayed = true;
+ usageOrVersionDisplayed = true;
if ((toolDescription != null) && (toolDescription.length() > 0))
{
buffer.append(wrapText(toolDescription, 79));
@@ -1008,6 +1039,17 @@
buffer.append(" where {options} include:");
buffer.append(EOL);
+ // --version is a builtin option
+ if (! shortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION))
+ {
+ buffer.append("-" + OPTION_SHORT_PRODUCT_VERSION + ", ");
+ }
+ buffer.append("--" + OPTION_LONG_PRODUCT_VERSION);
+ buffer.append(EOL);
+ buffer.append(" ");
+ buffer.append( getMessage(MSGID_DESCRIPTION_PRODUCT_VERSION));
+ buffer.append(EOL);
+
for (Argument a : argumentList)
{
// If this argument is hidden, then skip it.
@@ -1191,16 +1233,17 @@
/**
- * 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 "-?".
+ * 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.
+ * @return {@code true} if the usage information has been displayed,
+ * or {@code false} if not.
*/
- public boolean usageDisplayed()
+ public boolean usageOrVersionDisplayed()
{
- return usageDisplayed;
+ return usageOrVersionDisplayed;
}
+
}
--
Gitblit v1.10.0