From 8af4770c261b54c3f12bb4e8fe14b6f6b567514b Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 30 Aug 2007 13:49:23 +0000
Subject: [PATCH] Make the --advanced dsconfig option a global option so that it is available to the global interactive mode.

---
 opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java    |    6 -
 opends/src/server/org/opends/server/util/cli/ErrorStreamConsoleApplication.java  |   10 +++
 opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java |    4 -
 opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java |    6 -
 opends/src/messages/messages/dsconfig.properties                                 |    8 --
 opends/src/server/org/opends/server/util/cli/OutputStreamConsoleApplication.java |   10 +++
 opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java        |   51 -----------------
 opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java  |    6 -
 opends/src/server/org/opends/server/util/cli/ConsoleApplication.java             |   10 +++
 opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java                 |   27 +++++++++
 10 files changed, 64 insertions(+), 74 deletions(-)

diff --git a/opends/src/messages/messages/dsconfig.properties b/opends/src/messages/messages/dsconfig.properties
index 0cf9cc7..4584909 100644
--- a/opends/src/messages/messages/dsconfig.properties
+++ b/opends/src/messages/messages/dsconfig.properties
@@ -247,12 +247,8 @@
  also be used as the value of the "%s" property: %s
 SEVERE_ERR_DSCFG_ERROR_UNABLE_TO_SET_NAMING_PROPERTY_1210=The property "%s" \
  cannot be set as it is defined implicitly by the name of the %s
-INFO_DSCFG_DESCRIPTION_ADVANCED_GET_1216=Modifies the display output to show \
- the advanced properties of the %s
-INFO_DSCFG_DESCRIPTION_ADVANCED_SET_1217=Allows the configuration of advanced \
- properties during interactive mode
-INFO_DSCFG_DESCRIPTION_ADVANCED_HELP_1218=Modifies the display output to show \
- the advanced properties of components
+INFO_DSCFG_DESCRIPTION_ADVANCED_1216=Allows the configuration of advanced \
+ components and properties
 SEVERE_ERR_DSCFG_ERROR_MISSING_NON_INTERACTIVE_ARG_1223=The argument "--%s" \
  must be specified when this application is used non-interactively
 SEVERE_ERR_DSCFG_ERROR_CANNOT_READ_CONSOLE_INPUT_1224=The response could not \
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
index 21bb850..6171137 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
@@ -411,10 +411,6 @@
     // Create the naming arguments.
     this.namingArgs = createNamingArgs(subCommand, c, true);
 
-    // Register common arguments.
-    registerAdvancedModeArgument(this.subCommand,
-        INFO_DSCFG_DESCRIPTION_ADVANCED_SET.get());
-
     // Create the --property argument which is used to specify
     // property values.
     this.propertySetArgument = new StringArgument(OPTION_DSCFG_LONG_SET,
@@ -657,7 +653,7 @@
             continue;
           }
 
-          if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
+          if (!app.isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
             continue;
           }
 
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
index 251a429..4f1dc52 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -249,6 +249,16 @@
   }
 
   /**
+   * The value for the long option advanced.
+   */
+  private static final String OPTION_DSCFG_LONG_ADVANCED = "advanced";
+
+  /**
+   * The value for the short option advanced.
+   */
+  private static final Character OPTION_DSCFG_SHORT_ADVANCED = null;
+
+  /**
    * The tracer object for the debug logger.
    */
   private static final DebugTracer TRACER = getTracer();
@@ -310,6 +320,9 @@
     return app.run(args);
   }
 
+  // The argument which should be used to request advanced mode.
+  private BooleanArgument advancedModeArgument;
+
   // Flag indicating whether or not the application environment has
   // already been initialized.
   private boolean environmentInitialized = false;
@@ -408,6 +421,15 @@
   /**
    * {@inheritDoc}
    */
+  public boolean isAdvancedMode() {
+    return advancedModeArgument.isPresent();
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
   public boolean isInteractive() {
     return !noPromptArgument.isPresent();
   }
@@ -486,6 +508,10 @@
           OPTION_LONG_NO_PROMPT,
           INFO_DESCRIPTION_NO_PROMPT.get());
 
+      advancedModeArgument = new BooleanArgument(OPTION_DSCFG_LONG_ADVANCED,
+          OPTION_DSCFG_SHORT_ADVANCED, OPTION_DSCFG_LONG_ADVANCED,
+          INFO_DSCFG_DESCRIPTION_ADVANCED.get());
+
       showUsageArgument = new BooleanArgument("showUsage", OPTION_SHORT_HELP,
           OPTION_LONG_HELP, INFO_DSCFG_DESCRIPTION_SHOW_GROUP_USAGE_SUMMARY
               .get());
@@ -497,6 +523,7 @@
       parser.addGlobalArgument(quietArgument);
       parser.addGlobalArgument(scriptFriendlyArgument);
       parser.addGlobalArgument(noPromptArgument);
+      parser.addGlobalArgument(advancedModeArgument);
 
       // Register any global arguments required by the management
       // context factory.
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
index ac1049b..80b8ef9 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
@@ -173,8 +173,6 @@
 
     // Register common arguments.
     registerPropertyNameArgument(this.subCommand);
-    registerAdvancedModeArgument(this.subCommand,
-        INFO_DSCFG_DESCRIPTION_ADVANCED_GET.get(r.getUserFriendlyName()));
     registerRecordModeArgument(this.subCommand);
     registerUnitSizeArgument(this.subCommand);
     registerUnitTimeArgument(this.subCommand);
@@ -282,7 +280,7 @@
         continue;
       }
 
-      if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
+      if (!app.isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
         continue;
       }
 
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
index 1fe6c6e..8450e4b 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/HelpSubCommandHandler.java
@@ -726,8 +726,6 @@
     subCommand.addArgument(inheritedModeArgument);
 
     // Register common arguments.
-    registerAdvancedModeArgument(this.subCommand,
-        INFO_DSCFG_DESCRIPTION_ADVANCED_HELP.get());
     registerPropertyNameArgument(this.subCommand);
 
     this.categoryMap =
@@ -983,7 +981,7 @@
             continue;
           }
 
-          if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
+          if (!app.isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
             continue;
           }
 
@@ -1087,7 +1085,7 @@
             continue;
           }
 
-          if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
+          if (!app.isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
             continue;
           }
 
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
index 521d5b6..f48289f 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -248,10 +248,6 @@
     // Create the naming arguments.
     this.namingArgs = createNamingArgs(subCommand, path, false);
 
-    // Register common arguments.
-    registerAdvancedModeArgument(this.subCommand,
-        INFO_DSCFG_DESCRIPTION_ADVANCED_SET.get());
-
     // Create the --set argument.
     this.propertySetArgument = new StringArgument(OPTION_DSCFG_LONG_SET,
         OPTION_DSCFG_SHORT_SET, OPTION_DSCFG_LONG_SET, false, true, true,
@@ -521,7 +517,7 @@
           continue;
         }
 
-        if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
+        if (!app.isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) {
           continue;
         }
 
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java b/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
index 61aff03..706f806 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -531,11 +531,6 @@
   public static final int MULTI_COLUMN_THRESHOLD = 8;
 
   /**
-   * The value for the long option advanced.
-   */
-  private static final String OPTION_DSCFG_LONG_ADVANCED = "advanced";
-
-  /**
    * The value for the long option property.
    */
   private static final String OPTION_DSCFG_LONG_PROPERTY = "property";
@@ -556,11 +551,6 @@
   private static final String OPTION_DSCFG_LONG_UNIT_TIME = "unit-time";
 
   /**
-   * The value for the short option advanced.
-   */
-  private static final Character OPTION_DSCFG_SHORT_ADVANCED = null;
-
-  /**
    * The value for the short option property.
    */
   private static final Character OPTION_DSCFG_SHORT_PROPERTY = null;
@@ -580,9 +570,6 @@
    */
   private static final char OPTION_DSCFG_SHORT_UNIT_TIME = 'M';
 
-  // The argument which should be used to request advanced mode.
-  private BooleanArgument advancedModeArgument;
-
   // The argument which should be used to specify zero or more
   // property names.
   private StringArgument propertyArgument;
@@ -935,22 +922,6 @@
 
 
   /**
-   * Determines whether the user requested advanced mode.
-   *
-   * @return Returns <code>true</code> if the user requested
-   *         advanced mode.
-   */
-  protected final boolean isAdvancedMode() {
-    if (advancedModeArgument != null) {
-      return advancedModeArgument.isPresent();
-    } else {
-      return false;
-    }
-  }
-
-
-
-  /**
    * Determines whether the user requested record-mode.
    *
    * @return Returns <code>true</code> if the user requested
@@ -1062,28 +1033,6 @@
 
 
   /**
-   * Registers the advanced mode argument with the sub-command.
-   *
-   * @param subCommand
-   *          The sub-command.
-   * @param description
-   *          The usage description message to be used for the
-   *          argument.
-   * @throws ArgumentException
-   *           If the advanced mode argument could not be registered.
-   */
-  protected final void registerAdvancedModeArgument(SubCommand subCommand,
-                                                    Message description)
-          throws ArgumentException
-  {
-    this.advancedModeArgument = new BooleanArgument(OPTION_DSCFG_LONG_ADVANCED,
-        OPTION_DSCFG_SHORT_ADVANCED, OPTION_DSCFG_LONG_ADVANCED, description);
-    subCommand.addArgument(advancedModeArgument);
-  }
-
-
-
-  /**
    * Registers the property name argument with the sub-command.
    *
    * @param subCommand
diff --git a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
index 7c32dff..0033045 100644
--- a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -249,6 +249,16 @@
 
 
   /**
+   * Indicates whether or not the user has requested advanced mode.
+   *
+   * @return Returns <code>true</code> if the user has requested
+   *         advanced mode.
+   */
+  public abstract boolean isAdvancedMode();
+
+
+
+  /**
    * Indicates whether or not the user has requested interactive
    * behavior.
    *
diff --git a/opends/src/server/org/opends/server/util/cli/ErrorStreamConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/ErrorStreamConsoleApplication.java
index 0d16256..bd76b3b 100644
--- a/opends/src/server/org/opends/server/util/cli/ErrorStreamConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/ErrorStreamConsoleApplication.java
@@ -58,6 +58,16 @@
    * {@inheritDoc}
    */
   @Override
+  public boolean isAdvancedMode() {
+    return app.isAdvancedMode();
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public boolean isInteractive() {
     return app.isInteractive();
   }
diff --git a/opends/src/server/org/opends/server/util/cli/OutputStreamConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/OutputStreamConsoleApplication.java
index e0aa77a..dba4987 100644
--- a/opends/src/server/org/opends/server/util/cli/OutputStreamConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/OutputStreamConsoleApplication.java
@@ -58,6 +58,16 @@
    * {@inheritDoc}
    */
   @Override
+  public boolean isAdvancedMode() {
+    return app.isAdvancedMode();
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public boolean isInteractive() {
     return app.isInteractive();
   }

--
Gitblit v1.10.0