You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2008/07/22 11:17:45 UTC
svn commit: r678688 - in /commons/proper/cli/branches/cli-1.x/src:
java/org/apache/commons/cli/ test/org/apache/commons/cli/
test/org/apache/commons/cli/bug/
Author: ebourg
Date: Tue Jul 22 02:17:44 2008
New Revision: 678688
URL: http://svn.apache.org/viewvc?rev=678688&view=rev
Log:
MissingArgumentException now references the option with the missing argument
Modified:
commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/MissingArgumentException.java
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/GnuParserTest.java
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java
commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI71Test.java
Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/MissingArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/MissingArgumentException.java?rev=678688&r1=678687&r2=678688&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/MissingArgumentException.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/MissingArgumentException.java Tue Jul 22 02:17:44 2008
@@ -26,6 +26,9 @@
*/
public class MissingArgumentException extends ParseException
{
+ /** The option requiring additional arguments */
+ private Option option;
+
/**
* Construct a new <code>MissingArgumentException</code>
* with the specified detail message.
@@ -36,4 +39,28 @@
{
super(message);
}
+
+ /**
+ * Construct a new <code>MissingArgumentException</code>
+ * with the specified detail message.
+ *
+ * @param option the option requiring an argument
+ * @since 1.2
+ */
+ public MissingArgumentException(Option option)
+ {
+ this("Missing argument for option: " + option.getKey());
+ this.option = option;
+ }
+
+ /**
+ * Return the option requiring an argument that wasn't provided
+ * on the command line.
+ *
+ * @since 1.2
+ */
+ public Option getOption()
+ {
+ return option;
+ }
}
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=678688&r1=678687&r2=678688&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 Tue Jul 22 02:17:44 2008
@@ -355,8 +355,7 @@
if ((opt.getValues() == null) && !opt.hasOptionalArg())
{
- throw new MissingArgumentException("Missing argument for option:"
- + opt.getKey());
+ throw new MissingArgumentException(opt);
}
}
Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParserTest.java?rev=678688&r1=678687&r2=678688&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParserTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/GnuParserTest.java Tue Jul 22 02:17:44 2008
@@ -102,6 +102,7 @@
catch (MissingArgumentException e)
{
caught = true;
+ assertEquals("option missing an argument", "b", e.getOption().getOpt());
}
assertTrue( "Confirm MissingArgumentException caught", caught );
Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java?rev=678688&r1=678687&r2=678688&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java Tue Jul 22 02:17:44 2008
@@ -122,6 +122,7 @@
catch (MissingArgumentException e)
{
caught = true;
+ assertEquals("option missing an argument", "b", e.getOption().getOpt());
}
assertTrue( "Confirm MissingArgumentException caught", caught );
Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI71Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI71Test.java?rev=678688&r1=678687&r2=678688&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI71Test.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/bug/BugCLI71Test.java Tue Jul 22 02:17:44 2008
@@ -67,8 +67,8 @@
try {
CommandLine line = parser.parse( options, args);
fail("MissingArgumentException expected");
- } catch(MissingArgumentException mae) {
- // expected
+ } catch(MissingArgumentException e) {
+ assertEquals("option missing an argument", "k", e.getOption().getOpt());
}
}