geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r594731 - in /geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp: CommandLineProcessor.java OptionDescriptor.java
Date Wed, 14 Nov 2007 00:39:55 GMT
Author: jdillon
Date: Tue Nov 13 16:39:54 2007
New Revision: 594731

URL: http://svn.apache.org/viewvc?rev=594731&view=rev
Log:
(GSHELL-36) Only override requirements if the handler is processed

Modified:
    geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
    geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java

Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java?rev=594731&r1=594730&r2=594731&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java
Tue Nov 13 16:39:54 2007
@@ -53,8 +53,6 @@
 
     private boolean stopAtNonOption = false;
     
-    private boolean overrideRequiredArguments = false;
-    
     public CommandLineProcessor(final Object bean) throws IllegalAnnotationError {
         assert bean != null;
 
@@ -160,7 +158,6 @@
             checkOptionNotInMap(alias);
         }
 
-        overrideRequiredArguments = (option.requireOverride() || overrideRequiredArguments)
? true : false;
         optionHandlers.add(handler);
 
     }
@@ -220,6 +217,7 @@
         Set<Handler> present = new HashSet<Handler>();
         int argIndex = 0;
         boolean processOptions = true;
+        boolean requireOverride = false;
 
         //
         // TODO: Need to rewrite some of this to allow more posix-style argument processing,
like --foo=bar and --foo bar, and -vvvv
@@ -266,11 +264,15 @@
             }
 
             try {
-                //
-                // HACK: Hook up the current handler to the params for error message rendering
-                //
+                //Hook up the current handler to the params for error message rendering
                 params.handler = handler;
 
+                // If this is an option which overrides requirements track it
+                if (!requireOverride && handler.descriptor instanceof OptionDescriptor)
{
+                    OptionDescriptor d = (OptionDescriptor) handler.descriptor;
+                    requireOverride = d.isRequireOverride();
+                }
+                
                 // Invoker the handler and then skip arguments which it has eatten up
                 int consumed = handler.handle(params);
                 params.skip(consumed);
@@ -283,14 +285,14 @@
             present.add(handler);
         }
         
-        // Ensure that all required option handlers are present
-        if (!overrideRequiredArguments) {
+        // Ensure that all required option handlers are present, unless a processed option
has overridden requirments
+        if (!requireOverride) {
 	        for (Handler handler : optionHandlers) {
 	            if (handler.descriptor.required() && !present.contains(handler)) {
 	                throw new ProcessingException(Messages.REQUIRED_OPTION_MISSING.format(handler.descriptor.toString()));
 	            }
 	        }
-	
+
 	        // Ensure that all required argument handlers are present
 	        for (Handler handler : argumentHandlers) {
 	            if (handler.descriptor.required() && !present.contains(handler)) {

Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java?rev=594731&r1=594730&r2=594731&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/OptionDescriptor.java
Tue Nov 13 16:39:54 2007
@@ -33,12 +33,15 @@
 
     private boolean argumentRequired;
 
+    private boolean requireOverride;
+
     public OptionDescriptor(final Option option, final boolean forceMultiValued) {
         super(option.description(), option.metaVar(), option.required(), option.handler(),
option.multiValued() || forceMultiValued);
     	
     	this.name = option.name();
     	this.aliases = option.aliases();
         this.argumentRequired = option.argumentRequired();
+        this.requireOverride = option.requireOverride();
     }
     
     public String name() {
@@ -52,7 +55,11 @@
     public boolean isArgumentRequired() {
         return argumentRequired;
     }
-    
+
+    public boolean isRequireOverride() {
+        return requireOverride;
+    }
+
     @Override
     public String toString() {
     	if (aliases != null && aliases.length > 0) {



Mime
View raw message