From 4bf3814d7eefb7ce4e17af501c3711e1b21b5e67 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Wed, 26 Sep 2007 15:56:11 +0000
Subject: [PATCH] Addresses issue 2143 which is intended to help with the readability of the usage statements by allowing options to be grouped logically by type.  Many of the utilities arguments have grown to such an extent that it is difficult to sort through the various types of arguments to find what you are looking for.  For instance the usage statement for the task schedulable arguments are mixed with the LDAP connection arguments which makes them difficult to ignore if they want to use the tool in offline mode.

---
 opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java |   79 +++++++++++++++++++++++----------------
 1 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
index 9acaa64..9e1fb63 100644
--- a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
@@ -29,7 +29,6 @@
 import org.opends.messages.MessageBuilder;
 
 
-import static org.opends.messages.ToolMessages.*;
 import static org.opends.messages.UtilityMessages.*;
 import static org.opends.server.tools.ToolConstants.*;
 import static org.opends.server.util.ServerConstants.*;
@@ -426,6 +425,24 @@
   public void addGlobalArgument(Argument argument)
          throws ArgumentException
   {
+    addGlobalArgument(argument, null);
+  }
+
+
+  /**
+   * Adds the provided argument to the set of global 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
+   *                             global or subcommand argument that has already
+   *                             been defined.
+   */
+  public void addGlobalArgument(Argument argument, ArgumentGroup group)
+         throws ArgumentException
+  {
+
     String argumentName = argument.getName();
     if (globalArgumentMap.containsKey(argumentName))
     {
@@ -514,6 +531,12 @@
     }
 
     globalArgumentList.add(argument);
+
+    if (group == null) {
+      group = getStandardGroup(argument);
+    }
+    group.addArgument(argument);
+    argumentGroups.add(group);
   }
 
   /**
@@ -1642,6 +1665,7 @@
     {
       buffer.append(wrapText(toolDescription, 79));
       buffer.append(EOL);
+      buffer.append(EOL);
     }
 
     String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
@@ -1733,42 +1757,33 @@
         buffer.append(INFO_SUBCMDPARSER_GLOBAL_HEADING.get());
         buffer.append(EOL);
       }
+      buffer.append(EOL);
 
-      // --version is a builtin option
-      boolean dashVAccepted = true;
-      if (globalShortIDMap.containsKey(OPTION_SHORT_PRODUCT_VERSION))
-      {
-        dashVAccepted = false;
-      }
-      else
-      {
-        for (SubCommand subCmd : subCommands.values())
-        {
-          if (subCmd.getArgument(OPTION_SHORT_PRODUCT_VERSION) != null)
-          {
-            dashVAccepted = false;
-            break;
-          }
-        }
-      }
-      if (dashVAccepted)
-      {
-        buffer.append("-" + OPTION_SHORT_PRODUCT_VERSION + ", ");
-      }
-      buffer.append("--" + OPTION_LONG_PRODUCT_VERSION);
-      buffer.append(EOL);
-      buffer.append("    ");
-      buffer.append( INFO_DESCRIPTION_PRODUCT_VERSION.get());
-      buffer.append(EOL);
+      boolean printGroupHeaders = printUsageGroupHeaders();
 
       // Display non-usage arguments.
-      for (Argument a : globalArgumentList) {
-        if (a.isHidden()) {
-          continue;
+      for (ArgumentGroup argGroup : argumentGroups)
+      {
+        if (argGroup.containsArguments() && printGroupHeaders)
+        {
+          // Print the groups description if any
+          Message groupDesc = argGroup.getDescription();
+          if (groupDesc != null && !Message.EMPTY.equals(groupDesc)) {
+            buffer.append(EOL);
+            buffer.append(wrapText(groupDesc.toString(), 79));
+            buffer.append(EOL);
+            buffer.append(EOL);
+          }
         }
 
-        if (!usageGroupArguments.containsKey(a)) {
-          printArgumentUsage(a, buffer);
+        for (Argument a : argGroup.getArguments()) {
+          if (a.isHidden()) {
+            continue;
+          }
+
+          if (!usageGroupArguments.containsKey(a)) {
+            printArgumentUsage(a, buffer);
+          }
         }
       }
 

--
Gitblit v1.10.0