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 2012/02/29 08:44:39 UTC

svn commit: r1294996 - in /oodt/trunk/cli: ./ src/main/java/org/apache/oodt/cas/cli/option/validator/

Author: bfoster
Date: Wed Feb 29 07:44:38 2012
New Revision: 1294996

URL: http://svn.apache.org/viewvc?rev=1294996&view=rev
Log:
- More updates to CAS-CLI help guide

Modified:
    oodt/trunk/cli/README.txt
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java

Modified: oodt/trunk/cli/README.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/README.txt?rev=1294996&r1=1294995&r2=1294996&view=diff
==============================================================================
--- oodt/trunk/cli/README.txt (original)
+++ oodt/trunk/cli/README.txt Wed Feb 29 07:44:38 2012
@@ -59,7 +59,7 @@ java \
   -Djava.util.logging.config.file=./logging.properties \
         -Dorg.apache.oodt.cas.cli.action.spring.config=./cmd-line-actions.xml \
         -Dorg.apache.oodt.cas.cli.option.spring.config=./cmd-line-options.xml \
-  MyMain $*
+  MyMain "$@"
 
 Then checkout cas-cli and in the same directory as its pom.xml file run (you will need to install maven 2 if you do not have it):
 
@@ -957,3 +957,168 @@ You should see:
   PrintMessageAction                  Prints out specified message
 
 -----------------------------------------------------------------------------------------------------------------
+
+At the begin of this guide it was stated that AdvancedCmdLineOption is a ValidatableCmdLineOption and HandleableCmdLineOption.  It has already been should how they are HandleableCmdLineOption by examples using handlers.  Now let's look at how they are ValidatableCmdLineOption.  Lets added another sub-option to --print which allows use to specify whatever message we want, so long as the argument value is "<someword> World":
+
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+  <bean id="execute" class="org.apache.oodt.cas.cli.option.ActionCmdLineOption">
+    <property name="shortOption" value="e" />
+    <property name="longOption" value="execute" />
+    <property name="description" value="Executes the specified action" />
+    <property name="hasArgs" value="true" />
+    <property name="required" value="true" />
+  </bean>
+
+  <bean id="manual" class="org.apache.oodt.cas.cli.option.HelpCmdLineOption">
+    <property name="shortOption" value="man" />
+    <property name="longOption" value="manual" />
+    <property name="description" value="Print out option help" />
+    <property name="hasArgs" value="false" />
+    <property name="required" value="false" />
+  </bean>
+
+  <bean id="listActions" class="org.apache.oodt.cas.cli.option.PrintSupportedActionsCmdLineOption">
+    <property name="shortOption" value="la" />
+    <property name="longOption" value="listActions" />
+    <property name="description" value="Print out supported actions" />
+    <property name="hasArgs" value="false" />
+    <property name="required" value="false" />
+  </bean>
+
+  <bean id="print" class="org.apache.oodt.cas.cli.option.GroupCmdLineOption">
+    <property name="shortOption" value="p" />
+    <property name="longOption" value="print" />
+    <property name="description" value="Declare that you wish to print a message" />
+    <property name="hasArgs" value="false" />
+    <property name="requirementRules">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="PrintMessageAction" p:relation="REQUIRED" />
+      </list>
+    </property>
+    <property name="subOptions">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+          p:option-ref="helloWorld" p:required="false" />
+        <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+          p:option-ref="byeWorld" p:required="false" />
+        <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+          p:option-ref="custom" p:required="false" />
+      </list>
+    </property>
+    </bean>
+
+  <bean id="helloWorld" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption" p:isSubOption="true">
+    <property name="shortOption" value="hw" />
+    <property name="longOption" value="helloWorld" />
+    <property name="description" value="Print out 'Hello World'" />
+    <property name="hasArgs" value="false" />
+    <property name="staticArgs">
+            <list>
+              <value>Hello World</value>
+            </list>
+        </property>
+    <property name="requirementRules">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="PrintMessageAction" p:relation="OPTIONAL" />
+      </list>
+    </property>
+    <property name="handler">
+      <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+        <property name="applyToActions">
+          <list>
+            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+              p:actionName="PrintMessageAction" p:methodName="setMessage" />
+          </list>
+        </property>
+      </bean>
+    </property>
+  </bean>
+
+  <bean id="byeWorld" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption" p:isSubOption="true">
+    <property name="shortOption" value="bw" />
+    <property name="longOption" value="byeWorld" />
+    <property name="description" value="Print out 'Bye World'" />
+    <property name="hasArgs" value="false" />
+    <property name="staticArgs">
+            <list>
+              <value>Bye World</value>
+            </list>
+        </property>
+    <property name="requirementRules">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="PrintMessageAction" p:relation="OPTIONAL" />
+      </list>
+    </property>
+    <property name="handler">
+      <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+        <property name="applyToActions">
+          <list>
+            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+              p:actionName="PrintMessageAction" p:methodName="setMessage" />
+          </list>
+        </property>
+      </bean>
+    </property>
+  </bean>
+
+  <bean id="custom" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption" p:isSubOption="true">
+    <property name="shortOption" value="c" />
+    <property name="longOption" value="custom" />
+    <property name="description" value="Print out custom message" />
+    <property name="hasArgs" value="true" />
+    <property name="requirementRules">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+          p:actionName="PrintMessageAction" p:relation="OPTIONAL" />
+      </list>
+    </property>
+    <property name="handler">
+      <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+        <property name="applyToActions">
+          <list>
+            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+              p:actionName="PrintMessageAction" p:methodName="setMessage" />
+          </list>
+        </property>
+      </bean>
+    </property>
+    <property name="validators">
+      <list>
+        <bean class="org.apache.oodt.cas.cli.option.validator.ArgRegExpCmdLineOptionValidator">
+          <property name="allowedArgs">
+            <list>
+                                                        <value>[^\s]+\sWorld</value>
+            </list>
+          </property>
+        </bean>
+      </list>
+    </property>
+  </bean>
+</beans>
+
+Now try executing:
+
+$ ./cli-test.sh -e PrintMessageAction -p -c "Hey World"
+
+You should see:
+Hey World
+
+Let's change it a bit:
+
+$ ./cli-test.sh -e PrintMessageAction -p -c "Hey There World"
+
+You should see:
+ERROR: Validation Failures: - Value 'Hey There World' is not allowed for option [longOption='custom',shortOption='c',description='Print out custom message'] - Allowed values = [[^\s]+\sWorld]
+
+The validator used was: org.apache.oodt.cas.cli.option.validator.ArgRegExpCmdLineOptionValidator.  This validator takes a java Pattern supported regular expression which is enforced against the options argument values.  Other supplied validators are:
+
+AllowedArgsCmdLineOptionValidator - Argument value must be one of the supplied values
+ClassExistsCmdLineOptionValidator - Expects the argument value to be an existing java class
+FileExistCmdLineOptionValidator - Expects the argument value to be an existing file

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=1294996&r1=1294995&r2=1294996&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java Wed Feb 29 07:44:38 2012
@@ -46,8 +46,8 @@ public class AllowedArgsCmdLineOptionVal
 
       for (String value : optionInst.getValues()) {
          if (!allowedArgs.contains(value)) {
-            return new Result(Grade.FAIL, "Option value " + value
-                  + " is not allowed for option "
+            return new Result(Grade.FAIL, "Value '" + value
+                  + "' is not allowed for option "
                   + optionInst.getOption().getLongOption()
                   + " - Allowed values = " + this.getAllowedArgs());
          }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=1294996&r1=1294995&r2=1294996&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java Wed Feb 29 07:44:38 2012
@@ -43,9 +43,8 @@ public class ArgRegExpCmdLineOptionValid
                continue TOP;
             }
          }
-         return new Result(Grade.FAIL, "Option1 value " + value
-               + " is not allowed for option "
-               + optionInst.getOption().getLongOption()
+         return new Result(Grade.FAIL, "Value '" + value
+               + "' is not allowed for option " + optionInst.getOption()
                + " - Allowed values = " + getAllowedArgs());
       }
       return new Result(Grade.PASS, "Success");

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java?rev=1294996&r1=1294995&r2=1294996&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java Wed Feb 29 07:44:38 2012
@@ -37,8 +37,8 @@ public class ClassExistsCmdLineOptionVal
          try {
             Class.forName(value);
          } catch (Exception e) {
-            return new Result(Grade.FAIL, "Option value " + value
-                  + " for option " + optionInst.getOption().getLongOption()
+            return new Result(Grade.FAIL, "Value '" + value
+                  + "' for option " + optionInst.getOption().getLongOption()
                   + " is not a valid class");
          }
       }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java?rev=1294996&r1=1294995&r2=1294996&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java Wed Feb 29 07:44:38 2012
@@ -38,8 +38,8 @@ public class FileExistCmdLineOptionValid
 
       for (String value : optionInst.getValues()) {
          if (!new File(value).exists()) {
-            return new Result(Grade.FAIL, "Option value " + value
-                  + " for option " + optionInst.getOption().getLongOption()
+            return new Result(Grade.FAIL, "Value '" + value
+                  + "' for option " + optionInst.getOption().getLongOption()
                   + " is not an existing file");
          }
       }