From beb0fcc101626f90436e0670b30e8164e57bf17a Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 28 Jun 2007 15:20:09 +0000
Subject: [PATCH] Complete fix for issue 1613 applying the fix also to the status-panel and status command lines.

---
 opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusCli.java                 |   71 +++++++++++++++++++----
 opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java       |   47 ++++++++++-----
 opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/resources/Resources.properties |   20 +-----
 3 files changed, 94 insertions(+), 44 deletions(-)

diff --git a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusCli.java b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusCli.java
index 8c9471a..5359a52 100644
--- a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusCli.java
+++ b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusCli.java
@@ -50,8 +50,15 @@
 import org.opends.statuspanel.ui.DatabasesTableModel;
 import org.opends.statuspanel.ui.ListenersTableModel;
 
+import static org.opends.server.messages.ToolMessages.*;
 import static org.opends.server.tools.ToolConstants.*;
+
 import org.opends.server.util.PasswordReader;
+import org.opends.server.util.ServerConstants;
+import org.opends.server.util.args.ArgumentParser;
+import org.opends.server.util.args.BooleanArgument;
+import org.opends.server.util.args.FileBasedArgument;
+import org.opends.server.util.args.StringArgument;
 
 /**
  * The class used to provide some CLI interface to display status.
@@ -374,21 +381,57 @@
 
   private void printUsage(PrintStream stream)
   {
-    String arg;
-    if (Utils.isWindows())
-    {
-      arg = Installation.WINDOWS_STATUSCLI_FILE_NAME;
-    } else
-    {
-      arg = Installation.UNIX_STATUSCLI_FILE_NAME;
+    ArgumentParser argParser =
+      new ArgumentParser(StatusPanelLauncher.class.getName(),
+        getI18n().getMsg("status-cli-usage-description"), false);
+    BooleanArgument showUsage;
+    StringArgument bindDN;
+    StringArgument bindPW;
+    FileBasedArgument bindPWFile;
+    String scriptName;
+    if (Utils.isWindows()) {
+      scriptName = Installation.WINDOWS_STATUSCLI_FILE_NAME;
+    } else {
+      scriptName = Installation.UNIX_STATUSCLI_FILE_NAME;
     }
-    /*
-     * This is required because the usage message contains '{' characters that
-     * mess up the MessageFormat.format method.
-     */
-    String msg = getMsg("status-cli-usage", true);
-    msg = msg.replace("{0}", arg);
-    stream.println(msg);
+    System.setProperty(ServerConstants.PROPERTY_SCRIPT_NAME, scriptName);
+    try
+    {
+      bindDN = new StringArgument("binddn", OPTION_SHORT_BINDDN,
+          OPTION_LONG_BINDDN, false, false, true,
+          OPTION_VALUE_BINDDN, null, null,
+          MSGID_STOPDS_DESCRIPTION_BINDDN);
+      argParser.addArgument(bindDN);
+
+      bindPW = new StringArgument("bindpw", OPTION_SHORT_BINDPWD,
+          OPTION_LONG_BINDPWD, false, false,
+          true,
+          OPTION_VALUE_BINDPWD, null, null,
+          MSGID_STOPDS_DESCRIPTION_BINDPW);
+      argParser.addArgument(bindPW);
+
+      bindPWFile = new FileBasedArgument("bindpwfile",
+          OPTION_SHORT_BINDPWD_FILE,
+          OPTION_LONG_BINDPWD_FILE,
+          false, false,
+          OPTION_VALUE_BINDPWD_FILE,
+          null, null,
+          MSGID_STOPDS_DESCRIPTION_BINDPWFILE);
+      argParser.addArgument(bindPWFile);
+      showUsage = new BooleanArgument("showusage", OPTION_SHORT_HELP,
+        OPTION_LONG_HELP,
+        MSGID_DESCRIPTION_USAGE);
+      argParser.addArgument(showUsage);
+      argParser.setUsageArgument(showUsage);
+
+      String msg = argParser.getUsage();
+      stream.println(msg);
+    }
+    catch (Throwable t)
+    {
+      System.out.println("ERROR: "+t);
+      t.printStackTrace();
+    }
   }
 
   private ServerStatusDescriptor createServerStatusDescriptor(String dn,
diff --git a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
index d502668..dc92fcf 100644
--- a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
+++ b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/StatusPanelLauncher.java
@@ -36,7 +36,12 @@
 import org.opends.quicksetup.util.Utils;
 import org.opends.quicksetup.Installation;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.util.ServerConstants;
+import org.opends.server.util.args.ArgumentParser;
+import org.opends.server.util.args.BooleanArgument;
 import org.opends.statuspanel.i18n.ResourceProvider;
+
+import static org.opends.server.messages.ToolMessages.*;
 import static org.opends.server.tools.ToolConstants.*;
 
 /**
@@ -89,7 +94,7 @@
         printVersion = true;
       }
     }
-    // We first check if we have to pribt the version
+    // We first check if we have to print the version
     if(printVersion)
     {
       try
@@ -209,21 +214,33 @@
 
   private static void printUsage(PrintStream stream)
   {
-    String arg;
-    if (Utils.isWindows())
-    {
-      arg = Installation.WINDOWS_STATUSPANEL_FILE_NAME;
-    } else
-    {
-      arg = Installation.UNIX_STATUSPANEL_FILE_NAME;
+    ArgumentParser argParser =
+      new ArgumentParser(StatusPanelLauncher.class.getName(),
+        getI18n().getMsg("status-panel-launcher-usage-description"), false);
+    BooleanArgument showUsage;
+    String scriptName;
+    if (Utils.isWindows()) {
+      scriptName = Installation.WINDOWS_STATUSPANEL_FILE_NAME;
+    } else {
+      scriptName = Installation.UNIX_STATUSPANEL_FILE_NAME;
     }
-    /*
-     * This is required because the usage message contains '{' characters that
-     * mess up the MessageFormat.format method.
-     */
-    String msg = getMsg("status-panel-launcher-usage");
-    msg = msg.replace("{0}", arg);
-    stream.println(msg);
+    System.setProperty(ServerConstants.PROPERTY_SCRIPT_NAME, scriptName);
+    try
+    {
+      showUsage = new BooleanArgument("showusage", OPTION_SHORT_HELP,
+        OPTION_LONG_HELP,
+        MSGID_DESCRIPTION_USAGE);
+      argParser.addArgument(showUsage);
+      argParser.setUsageArgument(showUsage);
+
+      String msg = argParser.getUsage();
+      stream.println(msg);
+    }
+    catch (Throwable t)
+    {
+      System.out.println("ERROR: "+t);
+      t.printStackTrace();
+    }
   }
 
   /**
diff --git a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/resources/Resources.properties b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/resources/Resources.properties
index 0588ec8..b3a28c5 100644
--- a/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/resources/Resources.properties
+++ b/opendj-sdk/opends/src/statuspanel/org/opends/statuspanel/resources/Resources.properties
@@ -31,12 +31,9 @@
 #
 # StatusPanel launcher
 #
-status-panel-launcher-usage=This utility may be used to display the Status \
-Panel window which displays basic server information and allows to \
-start, stop and restart the server.\n\
-Usage:  {0} {options}\n        where {options} include:\n\
--V, --version\n    Display Directory Server version information.\n\
--?, -H, --help\n    Display this usage information.
+status-panel-launcher-usage-description=This utility may be used to display \
+the Status Panel window which displays basic server information and allows to \
+start, stop and restart the server.
 status-panel-launcher-gui-launch-failed=Could not launch Status Panel.  Check \
 that you have access to the display.
 status-panel-launcher-gui-launch-failed-details=Could not launch Status \
@@ -172,15 +169,8 @@
 file {0}.  Check that the file path is correct, that you have access rights to \
 it and that it contains a password.
 cli-status-ldapauth-password-prompt=Password for user {0}:  
-status-cli-usage=This utility may be used to display basic server \
-information\n\n\
-Usage:  {0} {options}\n        where {options} include:\n\
--V, --version\n    Display Directory Server version information\n\
--D {bindDN}, --bindDN {bindDN}\n    Bind DN\n\
--w {bindPassword}, --bindPassword {bindPassword}\n    Bind password\n\
--j {bindPasswordFile}, --bindPasswordFile {bindPasswordFile}\n    Bind \
-password file\n\
--?, -H , --help\n    Display this usage information.
+status-cli-usage-description=This utility may be used to display basic server \
+information
 not-available-authentication-required-cli-label=<not available> (*)
 not-available-authentication-required-cli-legend=* Information only available \
 if you provide authentication information when launching the status \

--
Gitblit v1.10.0