commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r695760 - /commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java
Date Tue, 16 Sep 2008 08:05:04 GMT
Author: ebourg
Date: Tue Sep 16 01:05:03 2008
New Revision: 695760

URL: http://svn.apache.org/viewvc?rev=695760&view=rev
Log:
Fixed testStopAtExpectedArg for PosixParser

Modified:
    commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java

Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java?rev=695760&r1=695759&r2=695760&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java Tue
Sep 16 01:05:03 2008
@@ -37,6 +37,9 @@
     /** specifies if bursting should continue */
     private boolean eatTheRest;
 
+    /** holder for the current option */
+    private Option currentOption;
+
     /** the command line Options */
     private Options options;
 
@@ -109,12 +112,14 @@
                 int pos = token.indexOf('=');
                 String opt = pos == -1 ? token : token.substring(0, pos); // --foo
 
-                if (!options.hasOption(opt) && stopAtNonOption)
+                if (!options.hasOption(opt))
                 {
-                    processNonOptionToken(token);
+                    processNonOptionToken(token, stopAtNonOption);
                 }
                 else
                 {
+                    currentOption = options.getOption(opt);
+                    
                     tokens.add(opt);
                     if (pos != -1)
                     {
@@ -130,27 +135,19 @@
             }
             else if (token.startsWith("-"))
             {
-                if (token.length() == 2)
+                if (token.length() == 2 || options.hasOption(token))
                 {
                     processOptionToken(token, stopAtNonOption);
                 }
-                else if (options.hasOption(token))
-                {
-                    tokens.add(token);
-                }
                 // requires bursting
                 else
                 {
                     burstToken(token, stopAtNonOption);
                 }
             }
-            else if (stopAtNonOption)
-            {
-                processNonOptionToken(token);
-            }
             else
             {
-                tokens.add(token);
+                processNonOptionToken(token, stopAtNonOption);
             }
 
             gobble(iter);
@@ -182,10 +179,14 @@
      *
      * @param value The current token
      */
-    private void processNonOptionToken(String value)
+    private void processNonOptionToken(String value, boolean stopAtNonOption)
     {
-        eatTheRest = true;
-        tokens.add("--");
+        if (stopAtNonOption && (currentOption == null || !currentOption.hasArg()))
+        {
+            eatTheRest = true;
+            tokens.add("--");
+        }
+
         tokens.add(value);
     }
 
@@ -203,11 +204,16 @@
      */
     private void processOptionToken(String token, boolean stopAtNonOption)
     {
-        if (!options.hasOption(token) && stopAtNonOption)
+        if (stopAtNonOption && !options.hasOption(token))
         {
             eatTheRest = true;
         }
 
+        if (options.hasOption(token))
+        {
+            currentOption = options.getOption(token);
+        }
+
         tokens.add(token);
     }
 
@@ -239,8 +245,6 @@
      */
     protected void burstToken(String token, boolean stopAtNonOption)
     {
-        Option currentOption;
-
         for (int i = 1; i < token.length(); i++)
         {
             String ch = String.valueOf(token.charAt(i));
@@ -259,7 +263,7 @@
             }
             else if (stopAtNonOption)
             {
-                processNonOptionToken(token.substring(i));
+                processNonOptionToken(token.substring(i), true);
                 break;
             }
             else



Mime
View raw message