[Japi-cvs] SF.net SVN: japi: [207] libs/argparser/trunk/src/net/sf/japi/io/args/ ArgParser.java
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-11-25 14:19:47
|
Revision: 207 http://svn.sourceforge.net/japi/?rev=207&view=rev Author: christianhujer Date: 2006-11-25 06:19:43 -0800 (Sat, 25 Nov 2006) Log Message: ----------- Some minor improvements. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-25 10:16:15 UTC (rev 206) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-25 14:19:43 UTC (rev 207) @@ -28,10 +28,9 @@ /** * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * TODO: automatic argument conversion for option method invocation. - * TODO: better handling of boolean arguments - * TODO: Handling of - for STDIN as input argument filestream - * TODO: Support for I18N/L10N + * @todo automatic argument conversion for option method invocation. + * @todo better handling of boolean arguments + * @todo Handling of - for STDIN as input argument filestream */ public class ArgParser { @@ -61,6 +60,7 @@ * @throws RequiredOptionsMissingException in case an option is missing * @throws TerminalException in case argument parsing was stopped * @throws MissingArgumentException in the required argument for an option was missing + * @throws UnknownOptionException In case an option was specified that's not supported. */ private ArgParser(final Command command, final String... args) throws TerminalException, RequiredOptionsMissingException, UnknownOptionException, MissingArgumentException { this.command = command; @@ -70,7 +70,7 @@ argIterator = argList.listIterator(); parse(); checkRequiredMethods(); - int returnCode = 0; + int returnCode; try { returnCode = command.run(argList); } catch (final Exception e) { @@ -148,6 +148,8 @@ /** * Parses arguments into an arguments container and invokes the Command's {@link Command#run(List<String>)} method. * @throws TerminalException in case argument parsing was stopped + * @throws MissingArgumentException In case a required argument was missing. + * @throws UnknownOptionException In case a given option is not known. */ private void parse() throws TerminalException, UnknownOptionException, MissingArgumentException { try { @@ -187,6 +189,7 @@ /** * Invoke the argument method for the current option. * @throws TerminalException in case the invoked exception was terminal + * @throws UnknownOptionException In case a given option is not known. */ private void invokeMethod() throws TerminalException, UnknownOptionException { final Method method = argumentMethods.get(currentOption); @@ -201,9 +204,10 @@ final String arg = argIterator.next(); method.invoke(command, arg); argIterator.remove(); + } else if (parameterCount == 0) { + method.invoke(command); } else { - assert parameterCount == 0; - method.invoke(command); + throw new IllegalArgumentException("The number of parameters for option methods must be 0 or 1."); } } catch (final IllegalAccessException e) { System.err.println(e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |