From 2ec070382a3dba82d6c5964287e023d87e8ec06c Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Thu, 04 Nov 2010 18:34:07 +0000
Subject: [PATCH] Sort arguments in usage help according to short name then long name.

---
 sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java b/sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java
index a96f75f..4dfc520 100644
--- a/sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java
+++ b/sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java
@@ -873,7 +873,52 @@
         }
       }
 
-      for (final Argument a : argGroup.getArguments())
+      final SortedSet<Argument> args = new TreeSet<Argument>(
+          new Comparator<Argument>()
+          {
+
+            /**
+             * {@inheritDoc}
+             */
+            public int compare(final Argument o1, final Argument o2)
+            {
+              final String s1;
+              final String s2;
+
+              if (o1.getShortIdentifier() != null)
+              {
+                s1 = o1.getShortIdentifier().toString();
+              }
+              else
+              {
+                s1 = o1.getLongIdentifier();
+              }
+
+              if (o2.getShortIdentifier() != null)
+              {
+                s2 = o2.getShortIdentifier().toString();
+              }
+              else
+              {
+                s2 = o2.getLongIdentifier();
+              }
+
+              final int res = s1.compareToIgnoreCase(s2);
+              if (res != 0)
+              {
+                return res;
+              }
+              else
+              {
+                // Lowercase options first then uppercase.
+                return -s1.compareTo(s2);
+              }
+            }
+
+          });
+      args.addAll(argGroup.getArguments());
+
+      for (final Argument a : args)
       {
         // If this argument is hidden, then skip it.
         if (a.isHidden())

--
Gitblit v1.10.0