Args Engine is a simple command line parsing engine for Java. The library has a single class and can be imported into any project of your choice easily. The only prerequisite, however, is that Java 1.5 or higher is required for the library to work.

This library works for applications which need to parse either (or both) short form (e.g. -h) or long form (e.g. --help) command line options. It also supports parsing valued options with the assumption that the value for an option follows the option itself (as in -out /usr/myhome/result.log).


args-1.0.jar ~ Binary 3.21 kB ~ Source 3.79 kB

API Usage

The API of Args Engine has been kept as simple as possible. The following self explanatory listing shows typical usage which should cater to most needs.

// Initiate the arguments engine.
ArgsEngine engine = new ArgsEngine();

// Configure the switches/options. Use true for valued options.
engine.add("-q", "--quiet");
engine.add("-o", "--redirect-output", true);
engine.add("-h", "--help");

// Perform the parsing. The 'args' is the String[] received by main method.

// Start fetching states of switches.
boolean quiet = engine.getBoolean("-q");

if(engine.getBoolean("-o")) {
    // For valued options, use getString.
    String redir = engine.getString("-o");

// Use getNonOptions to filter out all options.
String[] nonOptions = engine.getNonOptions();

Listing 1: Java code showing the Args Engine in use.

That's about the Args Engine.


comments powered by Disqus