Table of contents
Using ArgParser is very simple. You have to define one (or more) classes that contain the options, create an ArgParser object, give it the option classes instances and analyse the command line
Here is how ArgParser is initialised and called
ArgParser p = new ArgParser("synopsis");
final Options options = new Options();
p.addOptions(options);
p.matchAllArgs(args);
where Options is an object that contains annotated members. Here is an example:
@Argument(name = "name", help = "The name of the component") String name;
After that, you can access the values that have been set in the instance of the Options class.
A complete "Hello World" example is:
public class HelloWorld {
@Argument(name = "name", help = "The name of the component")
String name;
public static void main(String[] args) throws ArgParserException {
new HelloWorld().run(args);
}
private void run(String[] args) throws ArgParserException {
ArgParser argParser = new ArgParser("java HelloWorld [options]");
argParser.addOptions(this);
argParser.matchAllArgs(args);
System.out.format("The name of the component is %s", name);
}
}
Here is the list of annotations that can be used with a pointer to the relevant documentation
In order to handle a variable, ArgParser depends on a handler. For example, an Integer object can be handled by an IntegerHandler that will automatically set its value if the corresponding argument is found in the command line.
To choose a handler, ArgParser follows the following steps and stops whenever a matching handler has been found:
The following types are automatically detected and what they expect:
Here is a list of handlers that are pre-defined but that need to be explicitely given to be used: