The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

Args4j 2.0.5 released

Posted by kohsuke on February 20, 2006 at 04:30 PM | Comments (0)

Args4j uses annotations to declaratively parse annotations. In 2.0.5, I made a few enhancements to the API. The first is a change to make it easier to define a custom option processing. In the previous versions, you write your option bean like this and argsj uses the type of the field to determine how to handle it:

public class MyOptions {
    
    @Option(name="-r",usage="recursively run something")
    private boolean recursive;

    @Option(name="-o",usage="output to this file")
    private File out;

In 2.0.5, you can override this by using handler:

public class MyOptions {

    @Option(name="-o",usage="output to this file",handler=MyFileOptionHandler.class)
    private File out;

This allows you to define a custom option handling semantics more easily. The other enhancement is the support for the "--" option --- the option terminator option, by using this mechanism. Specifically, you can now write:

class Foo {
  @Argument
  @Option(name="--",handler=StopOptionHandler.class)
  List args;
  
  @Option(name="-n")
  int n;
}

With this, the command line -n 5 abc def would parse into n=5, args={"abc",def"}, but -- -n 5 abc def would parse into n=0, args={"-n","5","abc","def"}. Also, Jan Materne has steadily adding new tests, so this version of argsj is tested better than ever.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds