Skip to main content

Args4j 2.0.5 released

Posted by kohsuke on February 20, 2006 at 4:30 PM PST

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.

Related Topics >>