From b1aa376919f5d5adb5747be5f46703032f639c98 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 04 Jul 2007 13:55:13 +0000
Subject: [PATCH] In the case where the user asked for the usage of the setup, uninstall or upgrade CLI, we were returning an error code systematically (the error code corresponding to an error in the data provided by the user).   With this modifications when the user asks for the usage explicitly we return an error code 0.  In addition to that, when the usage is asked explicitly in the command line  for the usage it is written to the standard output.  When we display the usage because of an error on the data provided by the user the usage is displayed in the error output.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
index e472b62..6727a5a 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
@@ -150,14 +150,20 @@
   }
 
   /**
-   * Prints a usage message to the terminal and exits
-   * with exit code QuickSetupCli.USER_DATA_ERROR.
-   * @param i18nMsg localized user message that will
-   * be printed to std error
+   * Prints a usage message to the terminal.
+   * @param i18nMsg localized user message that will be printed to the terminal.
+   * @param toStdErr whether the message must be printed to the standard error
+   * or the standard output.
    */
-  protected void printUsage(String i18nMsg) {
-    System.err.println(i18nMsg);
-    System.exit(QuickSetupCli.USER_DATA_ERROR);
+  protected void printUsage(String i18nMsg, boolean toStdErr) {
+    if (toStdErr)
+    {
+      System.err.println(i18nMsg);
+    }
+    else
+    {
+      System.out.println(i18nMsg);
+    }
   }
 
   /**
@@ -255,14 +261,14 @@
     QuickSetupCli cli = new QuickSetupCli(cliApp, args);
     int returnValue = cli.run();
     if (returnValue == QuickSetupCli.USER_DATA_ERROR) {
-      printUsage();
+      printUsage(true);
+      System.exit(QuickSetupCli.USER_DATA_ERROR);
     }
     return returnValue;
   }
 
   /**
-   * Prints the version statement to terminal and exits
-   * with an error code.
+   * Prints the version statement to standard output terminal.
    */
   private void printVersion()
   {
@@ -272,8 +278,10 @@
   /**
    * Prints a usage statement to terminal and exits with an error
    * code.
+   * @param toStdErr whether the message must be printed to the standard error
+   * or the standard output.
    */
-  protected abstract void printUsage();
+  protected abstract void printUsage(boolean toStdErr);
 
   /**
    * Creates a CLI application that will be run if the
@@ -300,15 +308,17 @@
   protected abstract void guiLaunchFailed(String logFileName);
 
   /**
-   * The main method which is called by the uninstall command lines.
+   * The main method which is called by the command lines.
    */
   public void launch() {
     if (shouldPrintVersion())
     {
       printVersion();
+      System.exit(QuickSetupCli.SUCCESSFUL);
     }
     else if (shouldPrintUsage()) {
-      printUsage();
+      printUsage(false);
+      System.exit(QuickSetupCli.SUCCESSFUL);
     } else if (isCli()) {
       CliApplication cliApp = createCliApplication();
       int exitCode = launchCli(args, cliApp);

--
Gitblit v1.10.0