About the CLI Library
This library provides a command line interpreter class that can be used as a service object to retrieve switches and non-switch arguments from a command line.
The CLI library was created because the existing alternatives such as Apache Commons CLI were either to heavyweight, or did not support the command switch style that we prefer at x1seven.
About x1seven Elements
The x1seven Elements projekt provides small focused components that make it easier to build enterprise applications.
All of the components in the x1seven Elements projekt are open-source under the LGPL version 2.1. This license allows x1seven Elements components to legally be used and distributed in other open-source and commercial projekts.
Linking in the CLI
The CLI is implemented in the class com.x1seven.hydrogen.cli.CommandLineInterpreter. The typical usage pattern is to create an instance within your main method and use it there to parse out the command switches that have been sent to your application. For example:
package myapp;
import com.x1seven.hydrogen.cli.
CommandLineInterpreter;
public Startup extends Object {
public static void main(String args[]) {
CommandLineInterpreter cli = new
CommandLineInterpreter();
// Get the verbose switch
boolean verbose = cli.getBooleanArgumentValue(
"v", "verbose", args, false);
// Get all non-switch arguments
String filenames[] = cli.getPlainValues(args);
// Call the real implementation
Startup s = new Startup();
s.start(verbose, filenames);
}
public start(boolean verbose,
String filenames[]) {
...
}
}
