You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/11/07 20:38:20 UTC

svn commit: r1198891 [1/2] - in /oodt/trunk/cli/src: main/java/org/apache/oodt/cas/cli/ main/java/org/apache/oodt/cas/cli/contruct/ main/java/org/apache/oodt/cas/cli/exception/ main/java/org/apache/oodt/cas/cli/help/ main/java/org/apache/oodt/cas/cli/h...

Author: bfoster
Date: Mon Nov  7 19:38:18 2011
New Revision: 1198891

URL: http://svn.apache.org/viewvc?rev=1198891&view=rev
Log:
- refactoring of CmdLineParser to be just a parser... introduce a CmdLineConstructor interface
- many CmdLineAction related changes
- introduced new Exceptions

Added:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java   (contents, props changed)
      - copied, changed from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/OptionHelpException.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java   (contents, props changed)
      - copied, changed from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineOptionParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java   (contents, props changed)
      - copied, changed from r1196726, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineOptionParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java   (contents, props changed)
      - copied, changed from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/Args.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java   (with props)
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineIterable.java   (contents, props changed)
      - copied, changed from r1196505, oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestArgs.java
Removed:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/OptionHelpException.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineOptionParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineOptionParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/Args.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestArgs.java
Modified:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineActionHelpPrinter.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineOptionsHelpPrinter.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOption.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOptionInstance.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/HandleableCmdLineOption.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/SimpleCmdLineOption.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToAction.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/require/ActionDependencyRule.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineArgs.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/parser/TestStdCmdLineOptionParser.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
    oodt/trunk/cli/src/testdata/cmd-line-options.xml

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java Mon Nov  7 19:38:18 2011
@@ -18,13 +18,11 @@ package org.apache.oodt.cas.cli;
 
 //OODT static imports
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findAction;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.findHelpOption;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.findPrintSupportedActionsOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedHelpOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedPrintSupportedActionsOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedActionOption;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedOption;
 
 //JDK imports
-import java.util.HashSet;
 import java.util.Set;
 
 //Apache imports
@@ -49,16 +47,11 @@ public class CmdLineArgs {
    private CmdLineAction specifiedAction;
    private Set<CmdLineAction> supportedActions;
 
-   private HelpCmdLineOption helpOption;
    private CmdLineOptionInstance helpOptionInst;
-   private ActionCmdLineOption actionOption;
    private CmdLineOptionInstance actionOptionInst;
-   private PrintSupportedActionsCmdLineOption psaOption;
    private CmdLineOptionInstance psaOptionInst;
    private Set<CmdLineOption> supportedOptions;
-   private Set<CmdLineOption> customSupportedOptions;
    private Set<CmdLineOptionInstance> specifiedOptions;
-   private Set<CmdLineOptionInstance> customSpecifiedOptions;
 
    /* package */CmdLineArgs(Set<CmdLineAction> supportedActions,
          Set<CmdLineOption> supportedOptions,
@@ -67,45 +60,17 @@ public class CmdLineArgs {
       Validate.notNull(supportedOptions);
       Validate.notNull(specifiedOptions);
 
-      helpOption = findHelpOption(supportedOptions);
-      helpOptionInst = findSpecifiedOption(helpOption, specifiedOptions);
+      helpOptionInst = findSpecifiedHelpOption(specifiedOptions);
+      psaOptionInst = findSpecifiedPrintSupportedActionsOption(specifiedOptions);
       actionOptionInst = findSpecifiedActionOption(specifiedOptions);
-      if (actionOptionInst == null) {
-         throw new IllegalArgumentException("Must specify action option!");
-      }
-      actionOption = (ActionCmdLineOption) actionOptionInst.getOption();
-      psaOption = findPrintSupportedActionsOption(supportedOptions);
-      psaOptionInst = findSpecifiedOption(psaOption, specifiedOptions);
-
-      this.supportedOptions = new HashSet<CmdLineOption>(supportedOptions);
-
-      customSupportedOptions = new HashSet<CmdLineOption>(supportedOptions);
-      customSupportedOptions.remove(helpOption);
-      customSupportedOptions.remove(actionOption);
-      customSupportedOptions.remove(psaOption);
-
-      this.specifiedOptions = new HashSet<CmdLineOptionInstance>(
-            specifiedOptions);
-
-      customSpecifiedOptions = new HashSet<CmdLineOptionInstance>(
-            specifiedOptions);
-      if (helpOptionInst != null) {
-         customSpecifiedOptions.remove(helpOptionInst);
-      }
-      customSpecifiedOptions.remove(actionOptionInst);
-      if (psaOptionInst != null) {
-         customSpecifiedOptions.remove(psaOptionInst);
-      }
 
+      this.supportedOptions = supportedOptions;
+      this.specifiedOptions = specifiedOptions;
       this.supportedActions = supportedActions;
-      specifiedAction = findAction(actionOptionInst, supportedActions);
-   }
 
-   /**
-    * @return The {@link HelpCmdLineOption}
-    */
-   public HelpCmdLineOption getHelpOption() {
-      return helpOption;
+      if (actionOptionInst != null) {
+         specifiedAction = findAction(actionOptionInst, supportedActions);
+      }
    }
 
    /**
@@ -117,13 +82,6 @@ public class CmdLineArgs {
    }
 
    /**
-    * @return The {@link ActionCmdLineOption}
-    */
-   public ActionCmdLineOption getActionOption() {
-      return actionOption;
-   }
-
-   /**
     * @return The {@link CmdLineOptionInstance} which is the specified
     *         {@link ActionCmdLineOption}, or null if it was not specified
     */
@@ -132,13 +90,6 @@ public class CmdLineArgs {
    }
 
    /**
-    * @return The {@link PrintSupportedActionsCmdLineOption}
-    */
-   public PrintSupportedActionsCmdLineOption getPrintSupportedActionsOption() {
-      return psaOption;
-   }
-
-   /**
     * @return The {@link CmdLineOptionInstance} which is the specified
     *         {@link PrintSupportedActionsCmdLineOption}, or null if it was not
     *         specified
@@ -155,14 +106,6 @@ public class CmdLineArgs {
    }
 
    /**
-    * @return Supported {@link CmdLineOption}s less Help, Action,
-    *         PrintSupportActions options
-    */
-   public Set<CmdLineOption> getCustomSupportedOptions() {
-      return customSupportedOptions;
-   }
-
-   /**
     * @return All specified {@link CmdLineOptionInstance}s
     */
    public Set<CmdLineOptionInstance> getSpecifiedOptions() {
@@ -170,14 +113,6 @@ public class CmdLineArgs {
    }
 
    /**
-    * @return Specified {@link CmdLineOptionInstance}s less Help, Action,
-    *         PrintSupportedActions option instances
-    */
-   public Set<CmdLineOptionInstance> getCustomSpecifiedOptions() {
-      return customSpecifiedOptions;
-   }
-
-   /**
     * @return All supported {@link CmdLineAction}s
     */
    public Set<CmdLineAction> getSupportedActions() {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java Mon Nov  7 19:38:18 2011
@@ -32,12 +32,16 @@ import org.apache.commons.lang.Validate;
 //OODT imports
 import org.apache.oodt.cas.cli.action.store.CmdLineActionStore;
 import org.apache.oodt.cas.cli.action.store.spring.SpringCmdLineActionStoreFactory;
+import org.apache.oodt.cas.cli.contruct.CmdLineConstructor;
+import org.apache.oodt.cas.cli.contruct.StdCmdLineConstructor;
+import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
 import org.apache.oodt.cas.cli.help.presenter.CmdLineOptionHelpPresenter;
 import org.apache.oodt.cas.cli.help.presenter.StdCmdLineOptionHelpPresenter;
 import org.apache.oodt.cas.cli.help.printer.CmdLineActionHelpPrinter;
 import org.apache.oodt.cas.cli.help.printer.CmdLineActionsHelpPrinter;
 import org.apache.oodt.cas.cli.help.printer.CmdLineOptionsHelpPrinter;
 import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionHelpPrinter;
+import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionsHelpPrinter;
 import org.apache.oodt.cas.cli.help.printer.StdCmdLineOptionsHelpPrinter;
 import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
@@ -46,10 +50,11 @@ import org.apache.oodt.cas.cli.option.He
 import org.apache.oodt.cas.cli.option.PrintSupportedActionsCmdLineOption;
 import org.apache.oodt.cas.cli.option.store.CmdLineOptionStore;
 import org.apache.oodt.cas.cli.option.store.spring.SpringCmdLineOptionStoreFactory;
-import org.apache.oodt.cas.cli.parser.CmdLineOptionParser;
-import org.apache.oodt.cas.cli.parser.StdCmdLineOptionParser;
-import org.apache.oodt.cas.cli.util.Args;
+import org.apache.oodt.cas.cli.parser.CmdLineParser;
+import org.apache.oodt.cas.cli.parser.StdCmdLineParser;
+import org.apache.oodt.cas.cli.util.CmdLineIterable;
 import org.apache.oodt.cas.cli.util.CmdLineUtils;
+import org.apache.oodt.cas.cli.util.ParsedArg;
 
 /**
  * A highly configurable utility class which supports parsing and handling of
@@ -63,7 +68,8 @@ import org.apache.oodt.cas.cli.util.CmdL
  */
 public class CmdLineUtility {
 
-   private CmdLineOptionParser parser;
+   private CmdLineParser parser;
+   private CmdLineConstructor constructor;
    private CmdLineOptionStore optionStore;
    private CmdLineActionStore actionStore;
    private CmdLineOptionsHelpPrinter optionHelpPrinter;
@@ -72,11 +78,13 @@ public class CmdLineUtility {
    private CmdLineOptionHelpPresenter helpPresenter;
 
    public CmdLineUtility() {
-      parser = new StdCmdLineOptionParser();
+      parser = new StdCmdLineParser();
+      constructor = new StdCmdLineConstructor();
       optionStore = new SpringCmdLineOptionStoreFactory().createStore();
       actionStore = new SpringCmdLineActionStoreFactory().createStore();
       optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
       actionHelpPrinter = new StdCmdLineActionHelpPrinter();
+      actionsHelpPrinter = new StdCmdLineActionsHelpPrinter();
       helpPresenter = new StdCmdLineOptionHelpPresenter();
    }
 
@@ -140,7 +148,7 @@ public class CmdLineUtility {
       helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
             CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
                   .get(0), cmdLineArgs.getSupportedActions()),
-            cmdLineArgs.getCustomSupportedOptions()));
+            cmdLineArgs.getSupportedOptions()));
    }
 
    public void printActionsHelp(CmdLineArgs cmdLineArgs) {
@@ -157,10 +165,14 @@ public class CmdLineUtility {
     *           The who will be parsed and executed.
     * @throws IOException
     *            On error parsing or executing the args.
+    * @throws CmdLineConstructionException 
+    *            On error constructing or executing the args.
     */
-   public void run(String[] args) throws IOException {
+   public void run(String[] args) throws IOException, CmdLineConstructionException {
       CmdLineArgs cmdLineArgs = parse(args);
-      if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
+      if (cmdLineArgs.getSpecifiedOptions().isEmpty()) {
+         printOptionHelp(cmdLineArgs);
+      } else if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
          execute(cmdLineArgs);
       }
    }
@@ -174,8 +186,10 @@ public class CmdLineUtility {
     * @return The parsed command line arguments in {@link CmdLineArgs} form.
     * @throws IOException
     *            On error parsing command line arguments.
+    * @throws CmdLineConstructionException 
+    *            On error constructing command line arguments.
     */
-   public CmdLineArgs parse(String[] args) throws IOException {
+   public CmdLineArgs parse(String[] args) throws IOException, CmdLineConstructionException {
       Validate.notNull(parser);
       Validate.notNull(optionStore);
 
@@ -203,7 +217,7 @@ public class CmdLineUtility {
 
       // Parse command line arguments.
       return new CmdLineArgs(actionStore.loadSupportedActions(), validOptions,
-            parser.parse(new Args(args), validOptions));
+            constructor.construct(new CmdLineIterable<ParsedArg>(parser.parse(args)), validOptions));
    }
 
    /**
@@ -215,7 +229,7 @@ public class CmdLineUtility {
     */
    public boolean handleHelp(CmdLineArgs cmdLineArgs) {
       if (cmdLineArgs.getHelpOptionInst() != null) {
-         if (cmdLineArgs.getHelpOptionInst().getSubOptions().isEmpty()) {
+         if (cmdLineArgs.getHelpOptionInst().getValues().isEmpty()) {
             printOptionHelp(cmdLineArgs);
          } else {
             printActionHelp(cmdLineArgs);
@@ -282,11 +296,11 @@ public class CmdLineUtility {
    public static Set<CmdLineOption> check(CmdLineArgs cmdLineArgs) {
       Set<CmdLineOption> requiredOptions = determineRequired(
             cmdLineArgs.getSpecifiedAction(),
-            cmdLineArgs.getCustomSupportedOptions());
+            cmdLineArgs.getSupportedOptions());
       HashSet<CmdLineOption> requiredOptionsNotSet = new HashSet<CmdLineOption>(
             requiredOptions);
       for (CmdLineOptionInstance specifiedOption : cmdLineArgs
-            .getCustomSpecifiedOptions()) {
+            .getSpecifiedOptions()) {
          requiredOptionsNotSet.remove(specifiedOption.getOption());
       }
       return requiredOptionsNotSet;
@@ -305,7 +319,7 @@ public class CmdLineUtility {
 
       HashSet<CmdLineOptionInstance> optionsFailed = new HashSet<CmdLineOptionInstance>();
       for (CmdLineOptionInstance optionInst : cmdLineArgs
-            .getCustomSpecifiedOptions()) {
+            .getSpecifiedOptions()) {
          if (!CmdLineUtils.validate(optionInst)) {
             optionsFailed.add(optionInst);
          }
@@ -321,7 +335,7 @@ public class CmdLineUtility {
     */
    public static void handle(CmdLineArgs cmdLineArgs) {
       for (CmdLineOptionInstance option : cmdLineArgs
-            .getCustomSpecifiedOptions()) {
+            .getSpecifiedOptions()) {
          CmdLineUtils.handle(cmdLineArgs.getSpecifiedAction(), option);
       }
    }

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java?rev=1198891&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java Mon Nov  7 19:38:18 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cli.contruct;
+
+//JDK imports
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
+import org.apache.oodt.cas.cli.option.CmdLineOption;
+import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.util.CmdLineIterable;
+import org.apache.oodt.cas.cli.util.ParsedArg;
+
+/**
+ * Responsible for constructing {@link CmdLineOptionInstance}s from parsed
+ * command line arguments.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public interface CmdLineConstructor {
+
+   public Set<CmdLineOptionInstance> construct(CmdLineIterable<ParsedArg> parsedArgs,
+         Set<CmdLineOption> validOptions) throws CmdLineConstructionException;
+
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/CmdLineConstructor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java?rev=1198891&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java Mon Nov  7 19:38:18 2011
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cli.contruct;
+
+//OODT static imports
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.getOptionByName;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.isHelpOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.isSubOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
+
+//JDK imports
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Stack;
+
+//Apache imports
+import org.apache.commons.lang.Validate;
+
+//OODT imports
+import org.apache.oodt.cas.cli.option.CmdLineOption;
+import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
+import org.apache.oodt.cas.cli.option.GroupSubOption;
+import org.apache.oodt.cas.cli.util.CmdLineIterable;
+import org.apache.oodt.cas.cli.util.ParsedArg;
+
+//Google imports
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * Standard {@link CmdLineConstructor} which support options and option
+ * groups.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class StdCmdLineConstructor implements CmdLineConstructor {
+
+   public Set<CmdLineOptionInstance> construct(CmdLineIterable<ParsedArg> parsedArgs,
+         Set<CmdLineOption> validOptions) {
+      HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
+
+      Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
+      for (ParsedArg arg : parsedArgs) {
+
+         if (arg.getType().equals(ParsedArg.Type.OPTION)) {
+
+            // check if option is a valid one
+            CmdLineOption option = getOptionByName(arg.getName(),
+                  validOptions);
+            if (option == null) {
+               throw new RuntimeException("Invalid option: '" + arg.getName() + "'");
+            }
+
+            // read found option
+            CmdLineOptionInstance specifiedOption = getOption(parsedArgs, option);
+
+            // Check if we are currently loading subOptions.
+            if (!groupOptions.isEmpty()) {
+
+               CmdLineOptionInstance currentGroup = groupOptions.peek();
+
+               // Check if option is a subOption for current group.
+               if (!isSubOption(currentGroup.getOption(), option)) {
+
+                  // Check if current group was expecting more subOptions.
+                  Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
+                  if (!requiredSubOptions.isEmpty()) {
+                     throw new RuntimeException(
+                           "Missing the following required subOptions for '"
+                                 + currentGroup.getOption()
+                                 + "': "
+                                 + sortOptionsByRequiredStatus(requiredSubOptions));
+
+                  } else if (currentGroup.getSubOptions().isEmpty()) {
+                     throw new RuntimeException(
+                           "Must specify a subOption for group option '"
+                                 + currentGroup.getOption() + "'");
+
+                  } else {
+
+                     // pop group and add to list of specified options.
+                     optionInstances.add(groupOptions.pop());
+                  }
+               } else {
+
+                  // Add option to current group subOptions.
+                  currentGroup.addSubOption(specifiedOption);
+                  continue;
+
+               }
+            }
+
+            if (option instanceof GroupCmdLineOption) {
+
+               // Push group as current group.
+               groupOptions.push(specifiedOption);
+
+            } else if (option.isSubOption()) {
+               throw new RuntimeException("Option '" + option
+                     + "' is a subOption, but was used at top level Option");
+
+            } else {
+
+               // Option good to go.
+               optionInstances.add(specifiedOption);
+            }
+         } else {
+            throw new RuntimeException("Invalid argument: '" + arg + "'");
+         }
+      }
+      while (!groupOptions.isEmpty()) {
+         CmdLineOptionInstance currentGroup = groupOptions.pop();
+         Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
+         if (!requiredSubOptions.isEmpty()) {
+            throw new RuntimeException(
+                  "Missing the following required subOptions for '"
+                        + currentGroup.getOption() + "': "
+                        + sortOptionsByRequiredStatus(requiredSubOptions));
+
+         } else {
+            optionInstances.add(currentGroup);
+         }
+      }
+      return optionInstances;
+   }
+
+   @VisibleForTesting
+   /* package */static CmdLineOptionInstance getOption(CmdLineIterable<ParsedArg> args,
+         CmdLineOption option) {
+      CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
+      specifiedOption.setOption(option);
+      List<String> values = getValues(args);
+      if (isHelpOption(option)) {
+         specifiedOption.setValues(values);         
+      } else if (option.hasArgs()) {
+         if (!values.isEmpty()) {
+            specifiedOption.setValues(values);
+         } else if (!option.hasStaticArgs()) {
+            throw new RuntimeException("Option " + option + " requires args");
+         }
+      } else if (!option.hasArgs() && !values.isEmpty()) {
+         throw new RuntimeException("Option " + option + " does not support args");
+      }
+      return specifiedOption;
+   }
+
+
+   @VisibleForTesting
+   /* package */static Set<CmdLineOption> verifyGroupHasRequiredSubOptions(
+         CmdLineOptionInstance group) {
+      Validate.isTrue(group.isGroup());
+
+      Set<CmdLineOption> missingSubOptions = new HashSet<CmdLineOption>();
+      TOP: for (GroupSubOption subOption : ((GroupCmdLineOption) group.getOption())
+            .getSubOptions()) {
+         if (subOption.isRequired()) {
+            for (CmdLineOptionInstance specifiedSubOption : group
+                  .getSubOptions()) {
+               if (specifiedSubOption.getOption().equals(subOption.getOption())) {
+                  continue TOP;
+               }
+            }
+            missingSubOptions.add(subOption.getOption());
+         }
+      }
+      return missingSubOptions;
+   }
+
+   @VisibleForTesting
+   /* package */static List<String> getValues(CmdLineIterable<ParsedArg> args) {
+      List<String> values = new ArrayList<String>();
+      ParsedArg nextValue = args.getCurrentArg();
+      while (nextValue != null && nextValue.getType().equals(ParsedArg.Type.VALUE)) {
+         values.add(nextValue.getName());
+         nextValue = args.incrementAndGet();
+      }
+      return values;
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java?rev=1198891&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java Mon Nov  7 19:38:18 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cli.exception;
+
+/**
+ * {@link Exception} thrown if there is an error during command line
+ * construction.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineConstructionException extends Exception {
+
+   private static final long serialVersionUID = 223647396006947261L;
+
+   public CmdLineConstructionException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineConstructionException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineConstructionException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java (from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/OptionHelpException.java)
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java?p2=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java&p1=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/OptionHelpException.java&r1=1196505&r2=1198891&rev=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/OptionHelpException.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java Mon Nov  7 19:38:18 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.oodt.cas.cli.help;
+package org.apache.oodt.cas.cli.exception;
 
 //JDK imports
 import java.io.IOException;

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/OptionHelpException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineActionHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineActionHelpPrinter.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineActionHelpPrinter.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineActionHelpPrinter.java Mon Nov  7 19:38:18 2011
@@ -19,15 +19,26 @@ package org.apache.oodt.cas.cli.help.pri
 //OODT static imports
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineOptional;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequiredSubOptions;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
 
 //JDK imports
 import java.util.List;
 import java.util.Set;
+import java.util.Stack;
 
 //OODT imports
+import org.apache.commons.lang.StringUtils;
 import org.apache.oodt.cas.cli.action.CmdLineAction;
+import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
+import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
+import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
+import org.apache.oodt.cas.cli.option.GroupSubOption;
+import org.apache.oodt.cas.cli.util.CmdLineUtils;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 
 /**
  * Standard help printer for printing help for a {@link CmdLineAction}.
@@ -47,14 +58,14 @@ public class StdCmdLineActionHelpPrinter
       Set<CmdLineOption> requiredOptions = determineRequired(action, options);
       List<CmdLineOption> sortedRequiredOptions = sortOptionsByRequiredStatus(requiredOptions);
       for (CmdLineOption option : sortedRequiredOptions) {
-         sb.append(getRequiredOptionHelp(option)).append("\n");
+         sb.append(getRequiredOptionHelp(action, option)).append("\n");
       }
 
       sb.append(getOptionalSubHeader()).append("\n");
       Set<CmdLineOption> optionalOptions = determineOptional(action, options);
       List<CmdLineOption> sortedOptionalOptions = sortOptionsByRequiredStatus(optionalOptions);
       for (CmdLineOption option : sortedOptionalOptions) {
-         sb.append(getOptionalOptionHelp(option)).append("\n");
+         sb.append(getOptionalOptionHelp(action, option)).append("\n");
       }
 
       sb.append(getFooter(action)).append("\n");
@@ -69,25 +80,72 @@ public class StdCmdLineActionHelpPrinter
       return " - Required:";
    }
 
-   protected String getRequiredOptionHelp(CmdLineOption option) {
-      return getOptionHelp(option);
+   protected String getRequiredOptionHelp(CmdLineAction action, CmdLineOption option) {
+      if (option instanceof GroupCmdLineOption) {
+         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
+      } else {
+         return getOptionHelp(action, option, "    ");
+      }
    }
 
    protected String getOptionalSubHeader() {
       return " - Optional:";
    }
 
-   protected String getOptionalOptionHelp(CmdLineOption option) {
-      return getOptionHelp(option);
+   protected String getOptionalOptionHelp(CmdLineAction action, CmdLineOption option) {
+      if (option instanceof GroupCmdLineOption) {
+         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
+      } else {
+         return getOptionHelp(action, option, "    ");
+      }
    }
 
    protected String getFooter(CmdLineAction action) {
       return "";
    }
 
-   protected String getOptionHelp(CmdLineOption option) {
-      return "    -" + option.getShortOption() + " [--"
-            + option.getLongOption() + "] "
-            + (option.hasArgs() ? "<" + option.getArgsDescription() + ">" : "");
+   protected String getOptionHelp(CmdLineAction action, CmdLineOption option, String indent) {
+      String argDescription = null;
+      if (option instanceof AdvancedCmdLineOption) {
+         argDescription = ((AdvancedCmdLineOption) option).getHandler().getArgDescription(action, option);
+      }
+
+      String argHelp = null;
+      if (option instanceof ActionCmdLineOption && option.hasArgs()) {
+         argHelp = action.getName();
+      } else {
+         argHelp = (option.hasArgs() ? " <" + (argDescription != null ?
+               argDescription : option.getArgsDescription()) + ">" : "");
+      }
+      return indent + "-" + option.getShortOption() + " [--"
+            + option.getLongOption() + "]"
+            + argHelp;
+   }
+
+   protected String getGroupHelp(CmdLineAction action,
+         GroupCmdLineOption option, String indent) {
+      String helpString = getOptionHelp(action, option, indent) + "\n";
+      Set<CmdLineOption> subOptions = determineRequiredSubOptions(action,
+            (GroupCmdLineOption) option);
+      if (subOptions.isEmpty()) {
+         if (!option.getSubOptions().isEmpty()) {
+            helpString += indent + "  One of:";
+            for (GroupSubOption subOption : option.getSubOptions()) {
+               helpString += "\n"
+                     + getOptionHelp(action, subOption.getOption(), "   "
+                           + indent);
+            }
+         }
+      } else {
+         for (CmdLineOption subOption : subOptions) {
+            if (subOption instanceof GroupCmdLineOption) {
+               helpString += getGroupHelp(action,
+                     (GroupCmdLineOption) subOption, "  " + indent);
+            } else {
+               helpString += getOptionHelp(action, subOption, "  " + indent);
+            }
+         }
+      }
+      return helpString;
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineOptionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineOptionsHelpPrinter.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineOptionsHelpPrinter.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/StdCmdLineOptionsHelpPrinter.java Mon Nov  7 19:38:18 2011
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.apache.commons.lang.StringUtils;
 
 //OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction;
 import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 
@@ -68,25 +69,25 @@ public class StdCmdLineOptionsHelpPrinte
             + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
             + StringUtils.rightPad((option.getLongOption() + argName), 49)
             + option.getDescription();
+
+      optionUsage = " " + optionUsage;
+
+      if (!option.getRequirementRules().isEmpty()) {
+         optionUsage += "\n"
+               + getFormattedString("Requirement Rules:", 62, 113)
+               + getFormattedString(option.getRequirementRules().toString(),
+                     63, 113);
+      }
+
       if (option instanceof AdvancedCmdLineOption) {
          if (((AdvancedCmdLineOption) option).hasHandler()) {
-            optionUsage += getFormattedString(((AdvancedCmdLineOption) option)
-                  .getHandler().getHelp(option), 62, 113);
+            optionUsage += "\n"
+                  + getFormattedString("Handler:", 62, 113)
+                  + getFormattedString(((AdvancedCmdLineOption) option)
+                        .getHandler().getHelp(option), 63, 113);
          }
       }
 
-      if (option.isRequired()) {
-         optionUsage = " " + optionUsage;
-      } else if (!option.getRequirementRules().isEmpty()) {
-         optionUsage = "{" + optionUsage + "}";
-         optionUsage += "\n"
-               + getFormattedString(
-                     "RequiredOptions: " + option.getRequirementRules(), 62,
-                     113);
-      } else {
-         optionUsage = "[" + optionUsage + "]";
-      }
-
       return optionUsage;
    }
 

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/ActionCmdLineOption.java Mon Nov  7 19:38:18 2011
@@ -31,9 +31,7 @@ public class ActionCmdLineOption extends
          String description, boolean hasArgs) {
       super(shortOption, longOption, description, hasArgs);
       this.setArgsDescription("action-name");
-      this.setRequired(true);
       this.setType(String.class);
       this.setPerformAndQuit(false);
    }
-
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOption.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOption.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOption.java Mon Nov  7 19:38:18 2011
@@ -57,11 +57,11 @@ public interface CmdLineOption {
 
    public String getArgsDescription();
 
-   public void setDefaultArgs(List<String> values);
+   public void setStaticArgs(List<String> values);
 
-   public List<String> getDefaultArgs();
+   public List<String> getStaticArgs();
 
-   public boolean hasDefaultArgs();
+   public boolean hasStaticArgs();
 
    public void setRequired(boolean required);
 

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOptionInstance.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOptionInstance.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOptionInstance.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/CmdLineOptionInstance.java Mon Nov  7 19:38:18 2011
@@ -98,8 +98,8 @@ public class CmdLineOptionInstance {
    }
 
    public List<String> getValues() {
-      if (values.isEmpty() && option.hasDefaultArgs()) {
-         return option.getDefaultArgs();
+      if (values.isEmpty() && option.hasStaticArgs()) {
+         return option.getStaticArgs();
       } else {
          return values;
       }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/HandleableCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/HandleableCmdLineOption.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/HandleableCmdLineOption.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/HandleableCmdLineOption.java Mon Nov  7 19:38:18 2011
@@ -30,4 +30,6 @@ public interface HandleableCmdLineOption
    public void setHandler(CmdLineOptionHandler handler);
 
    public CmdLineOptionHandler getHandler();
+
+   public boolean hasHandler();
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/SimpleCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/SimpleCmdLineOption.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/SimpleCmdLineOption.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/SimpleCmdLineOption.java Mon Nov  7 19:38:18 2011
@@ -48,7 +48,7 @@ public class SimpleCmdLineOption impleme
 
    private boolean hasArgs;
 
-   private List<String> defaultArgs;
+   private List<String> staticArgs;
 
    private boolean performAndQuit;
 
@@ -132,16 +132,16 @@ public class SimpleCmdLineOption impleme
       return argsDescription;
    }
 
-   public void setDefaultArgs(List<String> defaultArgs) {
-      this.defaultArgs = defaultArgs;
+   public void setStaticArgs(List<String> staticArgs) {
+      this.staticArgs = staticArgs;
    }
 
-   public List<String> getDefaultArgs() {
-      return defaultArgs;
+   public List<String> getStaticArgs() {
+      return staticArgs;
    }
 
-   public boolean hasDefaultArgs() {
-      return defaultArgs != null;
+   public boolean hasStaticArgs() {
+      return staticArgs != null;
    }
 
    public void setRequired(boolean required) {
@@ -188,7 +188,7 @@ public class SimpleCmdLineOption impleme
 
    @Override
    public int hashCode() {
-      return shortOption.hashCode();
+      return longOption.hashCode();
    }
 
    public String toString() {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToAction.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToAction.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToAction.java Mon Nov  7 19:38:18 2011
@@ -26,6 +26,8 @@ public class ApplyToAction {
 
    private String actionName;
    private String methodName;
+   private String description;
+   private String argDescription;
 
    public ApplyToAction() {
    }
@@ -50,4 +52,24 @@ public class ApplyToAction {
    public void setMethodName(String methodName) {
       this.methodName = methodName;
    }
+
+   public String getDescription() {
+      return description;
+   }
+
+   public void setDescription(String description) {
+      this.description = description;
+   }
+
+   public String getArgDescription() {
+      return argDescription;
+   }
+
+   public void setArgDescription(String argDescription) {
+      this.argDescription = argDescription;
+   }
+
+   public String toString() {
+      return actionName + " : " + methodName;
+   }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/ApplyToActionHandler.java Mon Nov  7 19:38:18 2011
@@ -33,6 +33,7 @@ import org.apache.oodt.cas.cli.option.Cm
 
 //Google imports
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
 
 /**
  * {@link CmdLineOptionHandler} which applies {@link CmdLineOption} values to
@@ -91,8 +92,42 @@ public class ApplyToActionHandler implem
       return null;
    }
 
+   @VisibleForTesting
+   protected String getDescription(String actionName) {
+      if (applyToActions != null) {
+         for (ApplyToAction applyToAction : applyToActions) {
+            if (applyToAction.getActionName().equals(actionName)) {
+               return applyToAction.getDescription();
+            }
+         }
+      }
+      return null;
+   }
+
+   @VisibleForTesting
+   protected String getArgDescription(String actionName) {
+      if (applyToActions != null) {
+         for (ApplyToAction applyToAction : applyToActions) {
+            if (applyToAction.getActionName().equals(actionName)) {
+               return applyToAction.getArgDescription();
+            }
+         }
+      }
+      return null;
+   }
+
    public String getHelp(CmdLineOption option) {
-      return "Will invoke 'set" + option.getLongOption()
-            + "' on action selected";
+      return "Will invoke '" + (option.isRepeating() ? "add" : "set")
+         + StringUtils.capitalize(option.getLongOption())
+         + "' on action selected, except for the following actions: "
+         + (applyToActions != null ? applyToActions : Lists.newArrayList());
+   }
+
+   public String getDescription(CmdLineAction action, CmdLineOption option) {
+      return getDescription(action.getName());
+   }
+
+   public String getArgDescription(CmdLineAction action, CmdLineOption option) {
+      return getArgDescription(action.getName());
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/CmdLineOptionHandler.java Mon Nov  7 19:38:18 2011
@@ -43,4 +43,6 @@ public interface CmdLineOptionHandler {
     */
    public abstract String getHelp(CmdLineOption option);
 
+   public abstract String getArgDescription(CmdLineAction action,
+         CmdLineOption option);
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/handler/SetJavaPropertiesHandler.java Mon Nov  7 19:38:18 2011
@@ -51,10 +51,6 @@ public class SetJavaPropertiesHandler im
       }
    }
 
-   public String getHelp(CmdLineOption option) {
-      return "Sets the following Java Properties: " + this.propertyNames;
-   }
-
    public void setPropertyNames(List<String> propertyNames) {
       this.propertyNames = propertyNames;
    }
@@ -62,4 +58,12 @@ public class SetJavaPropertiesHandler im
    public List<String> getPropertyNames() {
       return propertyNames;
    }
+
+   public String getHelp(CmdLineOption option) {
+      return "Sets the following Java Properties: " + this.propertyNames;
+   }
+
+   public String getArgDescription(CmdLineAction action, CmdLineOption option) {
+      return null;
+   }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/require/ActionDependencyRule.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/require/ActionDependencyRule.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/require/ActionDependencyRule.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/require/ActionDependencyRule.java Mon Nov  7 19:38:18 2011
@@ -59,10 +59,15 @@ public class ActionDependencyRule implem
    public Relation getRelation(CmdLineAction action) {
       Validate.notNull(actionName);
       Validate.notNull(relation);
+      Validate.notNull(action);
 
       if (action.getName().equals(actionName)) {
          return relation;
       }
       return Relation.NONE;
    }
+
+   public String toString() {
+      return actionName + " : " + relation;
+   }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java Mon Nov  7 19:38:18 2011
@@ -17,7 +17,6 @@
 package org.apache.oodt.cas.cli.option.store.spring;
 
 //JDK imports
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -29,6 +28,8 @@ import org.apache.oodt.cas.cli.option.st
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
+import com.google.common.collect.Sets;
+
 /**
  * Spring Framework based {@link CmdLineOptionStore}.
  * 
@@ -46,7 +47,13 @@ public class SpringCmdLineOptionStore im
       @SuppressWarnings("unchecked")
       Map<String, CmdLineOption> optionsMap = appContext
             .getBeansOfType(CmdLineOption.class);
-      return new HashSet<CmdLineOption>(optionsMap.values());
+      Set<CmdLineOption> supportedOptions = Sets.newHashSet();
+      for (CmdLineOption option : optionsMap.values()) {
+         if (!option.isSubOption()) {
+            supportedOptions.add(option);
+         }
+      }
+      return supportedOptions;
    }
 
    protected ApplicationContext getApplicationContext() {

Copied: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java (from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineOptionParser.java)
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java?p2=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java&p1=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineOptionParser.java&r1=1196505&r2=1198891&rev=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineOptionParser.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java Mon Nov  7 19:38:18 2011
@@ -18,12 +18,10 @@ package org.apache.oodt.cas.cli.parser;
 
 //JDK imports
 import java.io.IOException;
-import java.util.Set;
+import java.util.List;
 
 //OODT imports
-import org.apache.oodt.cas.cli.option.CmdLineOption;
-import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
-import org.apache.oodt.cas.cli.util.Args;
+import org.apache.oodt.cas.cli.util.ParsedArg;
 
 /**
  * Command Line parser which parse command line arguments into a {@link Set} of
@@ -31,9 +29,8 @@ import org.apache.oodt.cas.cli.util.Args
  * 
  * @author bfoster (Brian Foster)
  */
-public interface CmdLineOptionParser {
+public interface CmdLineParser {
 
-   public Set<CmdLineOptionInstance> parse(Args args,
-         Set<CmdLineOption> validOptions) throws IOException;
+   public List<ParsedArg> parse(String[] args) throws IOException;
 
 }

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java (from r1196726, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineOptionParser.java)
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java?p2=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java&p1=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineOptionParser.java&r1=1196726&r2=1198891&rev=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineOptionParser.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java Mon Nov  7 19:38:18 2011
@@ -14,192 +14,55 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.oodt.cas.cli.parser;
 
-//OODT static imports
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.findHelpOption;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.getOptionByName;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.isSubOption;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
-
 //JDK imports
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-import java.util.Stack;
 
 //OODT imports
-import org.apache.commons.lang.Validate;
-import org.apache.oodt.cas.cli.help.OptionHelpException;
-import org.apache.oodt.cas.cli.option.CmdLineOption;
-import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
-import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
-import org.apache.oodt.cas.cli.option.GroupSubOption;
-import org.apache.oodt.cas.cli.util.Args;
+import org.apache.oodt.cas.cli.util.ParsedArg;
 
 //Google imports
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
 
 /**
  * Standard Command-line parser which parser command line options of the form
- * --longOption -shortOption. Supports group options, options with values, and
- * without values.
+ * --longOption or -shortOption followed by 0 or more values.
  * 
  * @author bfoster (Brian Foster)
  */
-public class StdCmdLineOptionParser implements CmdLineOptionParser {
+public class StdCmdLineParser implements CmdLineParser {
 
-   public Set<CmdLineOptionInstance> parse(Args args,
-         Set<CmdLineOption> validOptions) throws IOException {
-      HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
-
-      CmdLineOption helpOption = findHelpOption(validOptions);
-      if (helpOption == null) {
-         throw new OptionHelpException(
-               "Must specify a help option in set of valid options");
-      }
-
-      if (args.numArgs() < 1) {
-         throw new OptionHelpException("Must specify options : type -"
-               + helpOption.getShortOption() + " or --"
-               + helpOption.getLongOption() + " for info");
-      }
+   public List<ParsedArg> parse(String[] args) throws IOException {
+      List<ParsedArg> parsedArgs = Lists.newArrayList();
 
-      Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
       for (String arg : args) {
-
          if (isOption(arg)) {
-
-            // check if option is a valid one
-            CmdLineOption option = getOptionByName(getOptionName(arg),
-                  validOptions);
-            if (option == null) {
-               throw new IOException("Invalid option: '" + arg + "'");
-            }
-
-            // read found option
-            CmdLineOptionInstance specifiedOption = getOption(args, option);
-
-            // Check if we are currently loading subOptions.
-            if (!groupOptions.isEmpty()) {
-
-               CmdLineOptionInstance currentGroup = groupOptions.peek();
-
-               // Check if option is a subOption for current group.
-               if (!isSubOption(currentGroup.getOption(), option)) {
-
-                  // Check if current group was expecting more subOptions.
-                  Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
-                  if (!requiredSubOptions.isEmpty()) {
-                     throw new IOException(
-                           "Missing the following required subOptions for '"
-                                 + currentGroup.getOption()
-                                 + "': "
-                                 + sortOptionsByRequiredStatus(requiredSubOptions));
-
-                  } else if (currentGroup.getSubOptions().isEmpty()) {
-                     throw new IOException(
-                           "Must specify a subOption for group option '"
-                                 + currentGroup.getOption() + "'");
-
-                  } else {
-
-                     // pop group and add to list of specified options.
-                     optionInstances.add(groupOptions.pop());
-                  }
-               } else {
-
-                  // Add option to current group subOptions.
-                  currentGroup.addSubOption(specifiedOption);
-                  continue;
-
-               }
-            }
-
-            if (option instanceof GroupCmdLineOption) {
-
-               // Push group as current group.
-               groupOptions.push(specifiedOption);
-
-            } else if (option.isSubOption()) {
-               throw new IOException("Option '" + option
-                     + "' is a subOption, but was used at top level Option");
-
-            } else {
-
-               // Option good to go.
-               optionInstances.add(specifiedOption);
-            }
+            parsedArgs.add(new ParsedArg(getOptionName(arg),
+                  ParsedArg.Type.OPTION));
          } else {
-            throw new IOException("Invalid argument: '" + arg + "'");
+            parsedArgs.add(new ParsedArg(arg, ParsedArg.Type.VALUE));
          }
       }
-      while (!groupOptions.isEmpty()) {
-         CmdLineOptionInstance currentGroup = groupOptions.pop();
-         Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
-         if (!requiredSubOptions.isEmpty()) {
-            throw new IOException(
-                  "Missing the following required subOptions for '"
-                        + currentGroup.getOption() + "': "
-                        + sortOptionsByRequiredStatus(requiredSubOptions));
-
-         } else {
-            optionInstances.add(currentGroup);
-         }
-      }
-      return optionInstances;
-   }
-
-   @VisibleForTesting
-   /* package */static Set<CmdLineOption> verifyGroupHasRequiredSubOptions(
-         CmdLineOptionInstance group) {
-      Validate.isTrue(group.isGroup());
-
-      Set<CmdLineOption> missingSubOptions = new HashSet<CmdLineOption>();
-      TOP: for (GroupSubOption subOption : ((GroupCmdLineOption) group.getOption())
-            .getSubOptions()) {
-         if (subOption.isRequired()) {
-            for (CmdLineOptionInstance specifiedSubOption : group
-                  .getSubOptions()) {
-               if (specifiedSubOption.getOption().equals(subOption.getOption())) {
-                  continue TOP;
-               }
-            }
-            missingSubOptions.add(subOption.getOption());
-         }
-      }
-      return missingSubOptions;
-   }
-
-   @VisibleForTesting
-   /* package */static CmdLineOptionInstance getOption(Args args,
-         CmdLineOption option) throws IOException {
-      CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
-      specifiedOption.setOption(option);
-      List<String> values = getValues(args);
-      if (option.hasArgs()) {
-         if (!values.isEmpty()) {
-            specifiedOption.setValues(values);
-         } else if (!option.hasDefaultArgs()) {
-            throw new IOException("Option " + option + " requires args");
-         }
-      } else if (!option.hasArgs() && !values.isEmpty()) {
-         throw new IOException("Option " + option + " does not support args");
-      }
-      return specifiedOption;
-   }
-
-   @VisibleForTesting
-   /* package */static List<String> getValues(Args args) {
-      List<String> values = new ArrayList<String>();
-      String nextValue = args.getCurrentArg();
-      while (nextValue != null && !isOption(nextValue)) {
-         values.add(nextValue);
-         nextValue = args.incrementAndGet();
-      }
-      return values;
+      return parsedArgs;
    }
 
    @VisibleForTesting

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java (from r1196505, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/Args.java)
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java?p2=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java&p1=oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/Args.java&r1=1196505&r2=1198891&rev=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/Args.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java Mon Nov  7 19:38:18 2011
@@ -17,36 +17,38 @@
 package org.apache.oodt.cas.cli.util;
 
 //JDK imports
-import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 
 //Apache imports
 import org.apache.commons.lang.Validate;
 
 /**
- * Wrapper class around command line arguments that allows multiple iterators
- * which affect each other, also allows you to increment iterators index
- * manually. all iterators handle termination safely.
+ * An {@link Iterable} which allows multiple concurrent iterators which affect
+ * each other, also allows you to increment iterators index manually. All
+ * iterators handle termination safely. However, the catch being that you can
+ * only iterate through this {@link Iterable} once, then you must create a new
+ * object of it to iterate over it again.
  * 
  * @author bfoster (Brian Foster)
  */
-public class Args implements Iterable<String> {
+public class CmdLineIterable<T> implements Iterable<T> {
    private int curIndex;
-   private String[] args;
+   private List<T> args;
 
-   public Args(String[] args) {
+   public CmdLineIterable(List<T> args) {
       Validate.notNull(args);
 
       curIndex = 0;
       this.args = args;
    }
 
-   public String[] getArgs() {
+   public List<T> getArgs() {
       return args;
    }
 
-   public String[] getArgsLeft() {
-      return Arrays.copyOfRange(args, curIndex, args.length);
+   public List<T> getArgsLeft() {
+      return args.subList(curIndex, args.size());
    }
 
    public int getCurrentIndex() {
@@ -61,45 +63,45 @@ public class Args implements Iterable<St
       curIndex--;
    }
 
-   public String incrementAndGet() {
+   public T incrementAndGet() {
       incrementIndex();
       return getCurrentArg();
    }
 
-   public String getAndIncrement() {
-      String next = getCurrentArg();
+   public T getAndIncrement() {
+      T next = getCurrentArg();
       incrementIndex();
       return next;
    }
 
    public int numArgs() {
-      return args.length;
+      return args.size();
    }
 
-   public String getArg(int index) {
-      return args[index];
+   public T getArg(int index) {
+      return args.get(index);
    }
 
    public boolean hasNext() {
-      return curIndex < args.length;
+      return curIndex < args.size();
    }
 
-   public String getCurrentArg() {
+   public T getCurrentArg() {
       if (hasNext()) {
-         return args[curIndex];
+         return args.get(curIndex);
       } else {
          return null;
       }
    }
 
-   public Iterator<String> iterator() {
-      return new Iterator<String>() {
+   public Iterator<T> iterator() {
+      return new Iterator<T>() {
 
          public boolean hasNext() {
-            return Args.this.hasNext();
+            return CmdLineIterable.this.hasNext();
          }
 
-         public String next() {
+         public T next() {
             if (!hasNext()) {
                throw new IndexOutOfBoundsException(curIndex + "");
             }

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java Mon Nov  7 19:38:18 2011
@@ -83,6 +83,21 @@ public class CmdLineUtils {
       return requiredOptions;
    }
 
+   public static Set<CmdLineOption> determineRequiredSubOptions(
+         CmdLineAction action, GroupCmdLineOption option) {
+      Validate.notNull(action);
+      Validate.notNull(option);
+
+      Set<CmdLineOption> requiredOptions = Sets.newHashSet();
+      for (GroupSubOption subOption : option.getSubOptions()) {
+         if (subOption.isRequired()
+               || isRequired(action, subOption.getOption())) {
+            requiredOptions.add(subOption.getOption());
+         }
+      }
+      return requiredOptions;
+   }
+
    /**
     * Determines if the given {@link CmdLineOption} is required because the
     * given {@link CmdLineAction} was specified.
@@ -97,10 +112,6 @@ public class CmdLineUtils {
       Validate.notNull(option);
       Validate.notNull(action);
 
-      if (option instanceof ActionCmdLineOption) {
-         return false;
-      }
-
       for (RequirementRule requirementRule : option.getRequirementRules()) {
          if (requirementRule.getRelation(action) == Relation.REQUIRED) {
             return true;
@@ -148,10 +159,6 @@ public class CmdLineUtils {
       Validate.notNull(action);
       Validate.notNull(option);
 
-      if (option instanceof ActionCmdLineOption) {
-         return false;
-      }
-
       for (RequirementRule requirementRule : option.getRequirementRules()) {
          if (requirementRule.getRelation(action) == Relation.OPTIONAL) {
             return true;

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java?rev=1198891&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java Mon Nov  7 19:38:18 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cli.util;
+
+/**
+ * 
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class ParsedArg {
+
+   public enum Type {
+      OPTION, VALUE;
+   }
+
+   private String name;
+   private Type type;
+
+   public ParsedArg(String name, Type type) {
+      this.name = name;
+      this.type = type;
+   }
+
+   public String getName() {
+      return name;
+   }
+
+   public Type getType() {
+      return type;
+   }
+
+   public String toString() {
+      return name + " : " + type;
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/ParsedArg.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineArgs.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineArgs.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineArgs.java Mon Nov  7 19:38:18 2011
@@ -24,7 +24,6 @@ import static com.google.common.collect.
 import static org.apache.oodt.cas.cli.test.util.TestUtils.createAction;
 import static org.apache.oodt.cas.cli.test.util.TestUtils.createActionOption;
 import static org.apache.oodt.cas.cli.test.util.TestUtils.createOptionInstance;
-import static org.apache.oodt.cas.cli.test.util.TestUtils.createSimpleOption;
 
 //JDK imports
 import java.util.Set;
@@ -38,9 +37,6 @@ import org.apache.oodt.cas.cli.option.Cm
 import org.apache.oodt.cas.cli.option.HelpCmdLineOption;
 import org.apache.oodt.cas.cli.option.PrintSupportedActionsCmdLineOption;
 
-//Google imports
-import com.google.common.collect.Sets;
-
 //JUnit imports
 import junit.framework.TestCase;
 
@@ -72,11 +68,9 @@ public class TestCmdLineArgs extends Tes
       CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, SUPPORTED_OPTIONS,
             specifiedOptions);
       assertEquals(TEST_ACTION_1, args.getSpecifiedAction());
-      assertEquals(ACTION_OPTION, args.getActionOption());
       assertEquals(args.getActionOptionInst(), specifiedAction);
-      assertEquals(HELP_OPTION, args.getHelpOption());
+      assertEquals(ACTION_OPTION, args.getActionOptionInst().getOption());
       assertNull(args.getHelpOptionInst());
-      assertEquals(PSA_ACTION, args.getPrintSupportedActionsOption());
       assertNull(args.getPrintSupportedActionsOptionInst());
    }
 
@@ -91,43 +85,11 @@ public class TestCmdLineArgs extends Tes
       // in set of supported actions.
       assertNull(args.getSpecifiedAction());
       // Verify that if did find the action option.
-      assertEquals(specifiedAction.getOption(), args.getActionOption());
+      assertEquals(specifiedAction.getOption(), args.getActionOptionInst()
+            .getOption());
       // Verify that if found the specified action even though it is not
       // supported.
       assertEquals(newArrayList("NotSupportedActionName"), args
             .getActionOptionInst().getValues());
    }
-
-   public void testGetCustomOptions() {
-      CmdLineOption customOption = createSimpleOption("test", false);
-      Set<CmdLineOption> options = newHashSet(SUPPORTED_OPTIONS);
-      options.add(customOption);
-      CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
-            Sets.newHashSet(createOptionInstance(ACTION_OPTION, TEST_ACTION_1.getName())));
-
-      // Test that custom supported options only contains the custom option.
-      assertEquals(newHashSet(customOption), args.getCustomSupportedOptions());
-   }
-
-   public void testGetCustomSpecifiedOptions() {
-      CmdLineOption customOption = createSimpleOption("test", false);
-      Set<CmdLineOption> options = newHashSet(SUPPORTED_OPTIONS);
-      options.add(customOption);
-      CmdLineOptionInstance specifiedOptions = createOptionInstance(
-            customOption, "test-values");
-      CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
-            newHashSet(specifiedOptions,
-                  createOptionInstance(ACTION_OPTION, TEST_ACTION_1.getName())));
-
-      // Test that custom specified options only contains the custom option.
-      assertEquals(newHashSet(specifiedOptions),
-            args.getCustomSpecifiedOptions());
-
-      args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
-            Sets.newHashSet(createOptionInstance(ACTION_OPTION, TEST_ACTION_1.getName())));
-
-      // Test that custom specified options is empty since custom option was not
-      // specified.
-      assertTrue(args.getCustomSpecifiedOptions().isEmpty());
-   }
 }

Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java Mon Nov  7 19:38:18 2011
@@ -60,7 +60,7 @@ public class TestCmdLineUtility extends 
       assertEquals(0, CmdLineUtility.check(args).size());
 
       // Expect fail.
-      args.getCustomSupportedOptions().add(
+      args.getSupportedOptions().add(
             TestUtils.createSimpleOption("ReqTestAction", true));
       assertEquals(1, CmdLineUtility.check(args).size());
    }

Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java?rev=1198891&r1=1198890&r2=1198891&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java Mon Nov  7 19:38:18 2011
@@ -68,9 +68,9 @@ public class TestSpringCmdLineOptionStor
       assertEquals("outputStream", advancedOption.getLongOption());
       assertEquals("Specify OutputStream", advancedOption.getDescription());
       assertTrue(advancedOption.hasArgs());
-      assertEquals(1, advancedOption.getDefaultArgs().size());
+      assertEquals(1, advancedOption.getStaticArgs().size());
       assertEquals(TestOutputStream.class.getCanonicalName(),
-            advancedOption.getDefaultArgs().get(0));
+            advancedOption.getStaticArgs().get(0));
       assertEquals("OutputStream classpath",
             advancedOption.getArgsDescription());
       assertEquals(1, advancedOption.getRequirementRules().size());