|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjargs.gnu.CommandLineApplicationParser<E>
E - Type of the command-line applicationpublic class CommandLineApplicationParser<E>
Starting-point for the annotation-based command-line option parsing.
Creates a CommandLineParser based on the annotations in the
command-line application class.
Example:
@CommandLineApplication(appName = "Application", enableHelp = true, showUsageOnExeption = true)
public class Application {
// -s,--show: show GUI
@CommandLineOption(longForm="show", shortForm="s", description="show GUI")
private boolean show; // default: false
// --text; allowed values [Lorem ipsum, foo]
@CommandLineOption()
@CommandLineValidator({ "Lorem ipsum", "foo" })
private String text; // default: "Lorem ipsum"
// --count
@CommandLineOption()
private Integer count; // default: null
// --f; interval [-10.3, 2.6]
@CommandLineOption()
@CommandLineValidator(min = "-10.3f", max = "2.6f")
private float f = 1.23f; // default: 1.23f
private Application() {
// required default constructor,
// can also be used to initialize fields
text = "Lorem ipsum";
}
public void start() {
if (show) {
doSomethingWithGUI();
} else {
doSomething();
}
}
public static void main(String[] args) {
CommandLineApplicationParser<Application> clap = CommandLineApplicationParser.of(Application.class);
Application app = clap.parse(args);
app.start();
}
}
| Method Summary | ||
|---|---|---|
java.io.PrintStream |
getPrintStream()
Returns the PrintStream used for CommandLineParser.printUsage(). |
|
java.lang.String[] |
getRemainingArgs()
|
|
boolean |
helpRequested()
|
|
static
|
of(java.lang.Class<T> annotatedObjectType)
|
|
static
|
of(java.lang.Class<T> annotatedObjectType,
java.util.Locale locale)
|
|
static
|
of(T annotatedObject)
|
|
static
|
of(T annotatedObject,
java.util.Locale locale)
|
|
E |
parse(java.lang.String[] args)
|
|
void |
setPrintStream(java.io.PrintStream out)
Sets the PrintStream used for CommandLineParser.printUsage(). |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public E parse(java.lang.String[] args)
throws IllegalOptionValueException,
UnknownOptionException
IllegalOptionValueException
UnknownOptionExceptionpublic boolean helpRequested()
public java.lang.String[] getRemainingArgs()
public void setPrintStream(java.io.PrintStream out)
PrintStream used for CommandLineParser.printUsage().
public java.io.PrintStream getPrintStream()
PrintStream used for CommandLineParser.printUsage().
public static <T> CommandLineApplicationParser<T> of(T annotatedObject)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static <T> CommandLineApplicationParser<T> of(T annotatedObject,
java.util.Locale locale)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static <T> CommandLineApplicationParser<T> of(java.lang.Class<T> annotatedObjectType)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static <T> CommandLineApplicationParser<T> of(java.lang.Class<T> annotatedObjectType,
java.util.Locale locale)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||