options - java lib for parsing command line options

Introduction

Java 1.5 introduces annotations and generics. Using these, options allows you to handle command line option parsing with very little effort. A simple example:

public class SimpleExample {
  @Option(shortName="n", 
          documentation="Name of the instance to create.")
  public String name;

  public static void main(String[] args) {
    SimpleExample me = new SimpleExample();
    OptionParser<SimpleExample> parser = 
            new OptionParser<SimpleExample>(me);
    try {
      parser.parse(args);
    } catch (OptionParseException e) {
      System.out.println(e.getMessage());
      System.out.println(parser.usage());
      System.exit(1);
    }
    System.out.println("Name: " + me.name);
  }
}

The point of this, apart from being compact, is that it does not intrude on the structure of your classes: no sub-classing, no interfaces to implement.

Documentation

Learn more here:

Releases

v1.1.1 (2015-07-06)

  • Allow private classes as value parsers.

v1.1 (2013-06-08)

  • Allow extending parsing to arbitrary classes by adding custom value parsers.
  • Bug fix for "--"; argument parsing no longer automatically stops.
  • options now present in central repository.

Version history.

Download options from Maven central repository.

Or, if you are a follower of maven, you would endow your pom.xml thus:

<project>
  ...
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>net.windwards</groupId>
        <artifactId>options</artifactId>
        <version>1.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

About

Please feedback to options at quest windwards net.

options is released under GNU Lesser General Public License, version 3.