Table of contents

Hello world example

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 object instance(s) and analyse the command line.

Here is how ArgParser is initialised and called:

		ArgParser p = new ArgParser("synopsis");
		final Options options = new Options();

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]");
		System.out.format("The name of the component is %s", name);

Overall view

List of exceptions

Exceptions can either be thrown when analyzing the code, or when parsing the command line.

  1. ArgParserException is the main exception from which all the others derive
  2.  StringScanException (deprecated);
  3. HandlerException in case of handler mismatch or when a handler was not found for a given class;
  4. UnmachedArgumentException when an argument that should have been set was not;
  5. ArgParseException is used when the command line contained an error

List of annotations

Here is the list of annotations that can be used with a pointer to the relevant documentation

  1. @Argument to define a new named command line argument
  2. @ArgumentClass for a variable member will parse the Class for more arguments
  3. @ArgumentRegexp Defines a regular expression that should be applied to decompose one or more arguments
  4. @ArgumentHandler associates a the Handler class to one ore more classes. This is useful to register new handlers.
  5. @ArgumentPostProcessor Defines a method that is called when the command line has been processed
  6. @CheckNumericIntervals to specify bounds for a numerical value
  7. @EnumValue Defines a possible value in an enumeration
  8. @OrderedArgument to define a new unnamed command line argument


Groups can be used to... group variables into logic units. This is useful when:

  • Generating the documentation;
  • Performing group actions (activation/desactivation)