[Japi-cvs] SF.net SVN: japi: [194] libs/argparser/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-11-06 22:28:16
|
Revision: 194 http://svn.sourceforge.net/japi/?rev=194&view=rev Author: christianhujer Date: 2006-11-06 14:27:57 -0800 (Mon, 06 Nov 2006) Log Message: ----------- Added isExiting and changed run() signature of Command. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.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 2006-11-06 22:26:24 UTC (rev 193) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-06 22:27:57 UTC (rev 194) @@ -29,8 +29,7 @@ * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * TODO: automatic argument conversion for option method invocation. - * TODO: Handling of --help - * TODO: Handling of --version + * TODO: better handling of boolean arguments * TODO: Handling of - for STDIN as input argument filestream * TODO: Support for I18N/L10N */ @@ -71,7 +70,16 @@ argIterator = argList.listIterator(); parse(); checkRequiredMethods(); - command.run(argList); + int returnCode = 0; + try { + returnCode = command.run(argList); + } catch (final Exception e) { + System.err.println(e); + returnCode = 1; + } + if (command.isExiting()) { + System.exit(returnCode); + } } /** Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-06 22:26:24 UTC (rev 193) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-11-06 22:27:57 UTC (rev 194) @@ -34,8 +34,16 @@ * Run this command. * This method is invoked by {@link ArgParser} once it is finnished with parsing the arguments. * @param args the argument strings that were not parsed away by {@link ArgParser}. + * @return return code suitable for passing to {@link System#exit(int)} (whether {@link System#exit(int)} is really invoked depends on the configuration of the {@link ArgParser}.) + * @throws Exception in case of problems during command execution. */ @SuppressWarnings({"InstanceMethodNamingConvention"}) - void run(@NotNull List<String> args); + int run(@NotNull List<String> args) throws Exception; + /** + * Return whether after running this Command, {@link System#exit(int)} should be invoked. + * @return <code>true</code> if {@link ArgParser} should invoke {@link System#exit(int)} after this command, otherwise <code>false</code>. + */ + boolean isExiting(); + } // 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 2006-11-06 22:26:24 UTC (rev 193) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-06 22:27:57 UTC (rev 194) @@ -35,9 +35,10 @@ /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) - public void run(final List<String> args) { + public int run(final List<String> args) { runCalled = true; this.args = args; + return 0; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |