[Japi-cvs] SF.net SVN: japi: [532] libs/argparser/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-07-13 20:14:49
|
Revision: 532 http://svn.sourceforge.net/japi/?rev=532&view=rev Author: christianhujer Date: 2007-07-13 13:14:47 -0700 (Fri, 13 Jul 2007) Log Message: ----------- [ 1751332 ] Required options check should be optional / configurable Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java libs/argparser/trunk/src/net/sf/japi/io/args/Command.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2007-07-10 19:13:49 UTC (rev 531) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2007-07-13 20:14:47 UTC (rev 532) @@ -140,7 +140,7 @@ * @throws RequiredOptionsMissingException in case a required command line argument was missing */ private void checkRequiredMethods() throws RequiredOptionsMissingException { - if (requiredMethods.size() > 0) { + if (command.isCheckRequiredOptions() && requiredMethods.size() > 0) { final List<String> missingOptions = new ArrayList<String>(); for (final Method requiredMethod : requiredMethods) { final Option option = requiredMethod.getAnnotation(Option.class); Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-07-10 19:13:49 UTC (rev 531) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-07-13 20:14:47 UTC (rev 532) @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collections; import java.util.Formatter; import java.util.List; import java.util.MissingResourceException; @@ -28,7 +29,6 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import java.util.Collections; import org.jetbrains.annotations.NotNull; /** @@ -46,11 +46,26 @@ */ private boolean exiting; + /** + * Whether to check for required options. + * @see Command#isCheckRequiredOptions() + */ + private boolean checkRequiredOptions = true; + /** Create a BasicCommand. */ protected BasicCommand() { } /** + * {@inheritDoc} + * @see System#exit(int) + * @see #setExiting(Boolean) + */ + @NotNull public Boolean isExiting() { + return exiting; + } + + /** * Exit Option. * Normally you wouldn't override this method. * The default behaviour is to not exit. @@ -66,13 +81,16 @@ this.exiting = exiting; } - /** - * {@inheritDoc} - * @see System#exit(int) - * @see #setExiting(Boolean) + /** {@inheritDoc} */ + public boolean isCheckRequiredOptions() { + return checkRequiredOptions; + } + + /** Sets whether the check for required options should be performed. + * @param checkRequiredOptions <code>true</code> if the check for required options should be performed, otherwise <code>false</code>. */ - @NotNull public Boolean isExiting() { - return exiting; + public void setCheckRequiredOptions(final boolean checkRequiredOptions) { + this.checkRequiredOptions = checkRequiredOptions; } /** Help Option. */ Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2007-07-10 19:13:49 UTC (rev 531) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2007-07-13 20:14:47 UTC (rev 532) @@ -45,4 +45,10 @@ */ Boolean isExiting(); + /** + * Return whether the check for required methods should be performed. + * @return <code>true</code> if {@link ArgParser} should perform a check on required methods on this command, otherwise <code>false</code>. + */ + boolean isCheckRequiredOptions(); + } // interface Command Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-07-10 19:13:49 UTC (rev 531) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-07-13 20:14:47 UTC (rev 532) @@ -148,6 +148,21 @@ } /** + * Tests whether it's not detected that a required option is missing if the command doesn't want it. + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) + * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1751332&group_id=149894&atid=776740">[ 1751332 ] Required options check should be optional / configurable</a> + */ + @Test + public void testCommandRequiredOptionMissingDisabled() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); + command.setCheckRequiredOptions(false); + ArgParser.parseAndRun(command); + } + + /** * Tests whether it's detected that an unknown option was given. * @throws RequiredOptionsMissingException (unexpected) * @throws TerminalException (unexpected) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |