Thread: [Japi-cvs] SF.net SVN: japi: [176] libs/argparser/trunk/src/net/sf/japi/io/args/ ArgParser.java
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-09-25 11:52:06
|
Revision: 176 http://svn.sourceforge.net/japi/?rev=176&view=rev Author: christianhujer Date: 2006-09-25 04:51:57 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Updated TODO text. 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-09-25 11:50:15 UTC (rev 175) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 11:51:57 UTC (rev 176) @@ -28,7 +28,7 @@ /** * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * TODO: arguments for options, argument conversion for the method invokation. + * TODO: automatic argument conversion for option method invokation. */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 22:30:28
|
Revision: 177 http://svn.sourceforge.net/japi/?rev=177&view=rev Author: christianhujer Date: 2006-09-25 15:30:23 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added more todos. 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-09-25 11:51:57 UTC (rev 176) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 22:30:23 UTC (rev 177) @@ -29,6 +29,9 @@ * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * TODO: automatic argument conversion for option method invokation. + * TODO: Handling of --help + * TODO: Handling of --version + * TODO: Handling of - for STDIN as input argument filestrea */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <chr...@us...> - 2006-11-26 23:47:22
|
Revision: 237 http://svn.sourceforge.net/japi/?rev=237&view=rev Author: christianhujer Date: 2006-11-26 15:47:21 -0800 (Sun, 26 Nov 2006) Log Message: ----------- Added todo about default option values. 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-26 23:46:28 UTC (rev 236) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-26 23:47:21 UTC (rev 237) @@ -32,6 +32,7 @@ * @todo automatic argument conversion for option method invocation. * @todo better handling of boolean arguments * @todo Handling of - for STDIN as input argument filestream + * @todo automatic printout of default values if property getter available. */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 23:09:23
|
Revision: 241 http://svn.sourceforge.net/japi/?rev=241&view=rev Author: christianhujer Date: 2006-11-29 15:09:22 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Fixed bug: missing argument didn't throw MissingArgumentException. 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-29 22:26:59 UTC (rev 240) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-11-29 23:09:22 UTC (rev 241) @@ -196,8 +196,9 @@ * 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. + * @throws MissingArgumentException In case the required argument for an option was missing. */ - private void invokeMethod() throws TerminalException, UnknownOptionException { + private void invokeMethod() throws TerminalException, UnknownOptionException, MissingArgumentException { final Method method = argumentMethods.get(currentOption); if (method == null) { throw new UnknownOptionException(currentOption); @@ -223,6 +224,8 @@ throw (TerminalException) cause; } System.err.println(e.getCause()); + } catch (final NoSuchElementException e) { + throw new MissingArgumentException(currentOption); } catch (final Exception e) { e.printStackTrace(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-15 20:56:08
|
Revision: 260 http://svn.sourceforge.net/japi/?rev=260&view=rev Author: christianhujer Date: 2006-12-15 12:56:07 -0800 (Fri, 15 Dec 2006) Log Message: ----------- Removed done todo comment. 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-12-14 23:09:33 UTC (rev 259) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-12-15 20:56:07 UTC (rev 260) @@ -30,7 +30,6 @@ /** * 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 automatic printout of default values if property getter available. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-30 17:11:55
|
Revision: 481 http://svn.sourceforge.net/japi/?rev=481&view=rev Author: christianhujer Date: 2007-06-30 10:11:53 -0700 (Sat, 30 Jun 2007) Log Message: ----------- Added missing @NotNull / @Nullable annotations. 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 2007-06-30 16:42:31 UTC (rev 480) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2007-06-30 17:11:53 UTC (rev 481) @@ -31,6 +31,8 @@ import java.util.NoSuchElementException; import java.util.Set; import net.sf.japi.io.args.converter.ConverterRegistry; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Parser for command line arguments. @@ -42,22 +44,22 @@ public final class ArgParser { /** The command to parse arguments to. */ - private final Command command; + @NotNull private final Command command; /** The command class. */ - private final Class<? extends Command> commandClass; + @NotNull private final Class<? extends Command> commandClass; /** The argument methods. */ - private final Map<String, Method> argumentMethods = new HashMap<String, Method>(); + @NotNull private final Map<String, Method> argumentMethods = new HashMap<String, Method>(); /** The required methods. */ - private final Set<Method> requiredMethods = new HashSet<Method>(); + @NotNull private final Set<Method> requiredMethods = new HashSet<Method>(); /** The iterator for the arguments. */ - private final ListIterator<String> argIterator; + @NotNull private final ListIterator<String> argIterator; /** The currently used option. */ - private String currentOption; + @Nullable private String currentOption; /** * Create a new ArgParser. @@ -69,7 +71,7 @@ * @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 { + private ArgParser(@NotNull final Command command, @NotNull final String... args) throws TerminalException, RequiredOptionsMissingException, UnknownOptionException, MissingArgumentException { this.command = command; commandClass = command.getClass(); initMethods(); @@ -132,7 +134,7 @@ * @param command Command to get option methods for * @return option methods for the command. */ - public static Set<Method> getOptionMethods(final Command command) { + @NotNull public static Set<Method> getOptionMethods(@NotNull final Command command) { return getOptionMethods(command.getClass()); } @@ -141,7 +143,7 @@ * @param commandClass Class of the Command to get option methods for * @return Option methods for the command class. */ - public static Set<Method> getOptionMethods(final Class<? extends Command> commandClass) { + @NotNull public static Set<Method> getOptionMethods(@NotNull final Class<? extends Command> commandClass) { final Method[] methods = commandClass.getMethods(); final Set<Method> optionMethods = new HashSet<Method>(); for (final Method method : methods) { @@ -240,7 +242,7 @@ * @param command Command to run * @param args Arguments to parse */ - public static void simpleParseAndRun(final Command command, final String... args) { + public static void simpleParseAndRun(@NotNull final Command command, @NotNull final String... args) { try { parseAndRun(command, args); } catch (final TerminalException e) { @@ -263,7 +265,7 @@ * @throws UnknownOptionException in case an option given was not known. * @throws MissingArgumentException in case an option was missing its argument */ - public static void parseAndRun(final Command command, final String... args) throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + public static void parseAndRun(@NotNull final Command command, @NotNull final String... args) throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { new ArgParser(command, args); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-09-08 20:22:23
|
Revision: 601 http://japi.svn.sourceforge.net/japi/?rev=601&view=rev Author: christianhujer Date: 2007-09-08 13:22:18 -0700 (Sat, 08 Sep 2007) Log Message: ----------- Added todos about -W and long options with one dash. 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 2007-08-27 20:42:02 UTC (rev 600) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2007-09-08 20:22:18 UTC (rev 601) @@ -43,6 +43,8 @@ * @todo better handling of boolean arguments * @todo Handling of - for STDIN as input argument filestream * @todo automatic printout of default values if property getter available. + * @todo Add -W long for gnu style long option parsing + * @todo Let the programmer choose whether long options with one dash should be supported (for Ragnor). If long options with one dash are supported, short option concatenation should be disabled. */ public final class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-09-09 10:50:04
|
Revision: 604 http://japi.svn.sourceforge.net/japi/?rev=604&view=rev Author: christianhujer Date: 2007-09-09 03:50:01 -0700 (Sun, 09 Sep 2007) Log Message: ----------- Added some more todos. 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 2007-09-08 20:23:33 UTC (rev 603) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2007-09-09 10:50:01 UTC (rev 604) @@ -45,6 +45,9 @@ * @todo automatic printout of default values if property getter available. * @todo Add -W long for gnu style long option parsing * @todo Let the programmer choose whether long options with one dash should be supported (for Ragnor). If long options with one dash are supported, short option concatenation should be disabled. + * @todo Abbreviation of long options as long as the abbreviation is unique + * @todo Treat a single dash not as option + * @todo Alternative way of getting arguments by a callback mechanism which processes single arguments. */ public final class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |