commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r661332 - in /commons/proper/cli/branches/cli-1.x/src: java/org/apache/commons/cli/Parser.java test/org/apache/commons/cli/ParseRequiredTest.java
Date Thu, 29 May 2008 13:35:20 GMT
Author: ebourg
Date: Thu May 29 06:35:20 2008
New Revision: 661332

URL: http://svn.apache.org/viewvc?rev=661332&view=rev
Log:
Parser no longer removes the required options from the Options instance (CLI-156)

Modified:
    commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java?rev=661332&r1=661331&r2=661332&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/Parser.java Thu May
29 06:35:20 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.cli;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -43,7 +44,7 @@
 
     protected void setOptions(final Options options) {
         this.options = options;
-        this.requiredOptions = options.getRequiredOptions();
+        this.requiredOptions = new ArrayList(options.getRequiredOptions());
     }
 
     protected Options getOptions() {

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java?rev=661332&r1=661331&r2=661332&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
(original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ParseRequiredTest.java
Thu May 29 06:35:20 2008
@@ -140,4 +140,26 @@
         }
     }
 
+    public void testReuseOptionsTwice() throws Exception
+    {
+        Options opts = new Options();
+		opts.addOption(OptionBuilder.isRequired().create('v'));
+
+		GnuParser parser = new GnuParser();
+
+        // first parsing
+        parser.parse(opts, new String[] { "-v" });
+
+        try
+        {
+            // second parsing, with the same Options instance and an invalid command line
+            parser.parse(opts, new String[0]);
+            fail("MissingOptionException not thrown");
+        }
+        catch (MissingOptionException e)
+        {
+            // expected
+        }
+    }
+
 }



Mime
View raw message