@Status(stage=DEVELOPMENT, unitTests=PARTIAL) @Review(by="Kees Schotanus", at="2009-09-28") public final class CommandLineProcessor extends Object
@Option(name = "c", optional = true)
public void setCreateFlag(final boolean createFlag) {
this.createFlag = createFlag;
}
@Option(name = "v", optional = true)
public void setViewFlag(final boolean viewFlag) {
this.viewFlag = viewFlag;
}
@Option(name = "f", optional = false)
public void setFileName(final String fileName) {
this.fileName = fileName;
}
@ProgramArguments()
public void setProgramArguments(final String [] programArguments) {
this.programArguments = programArguments.clone();
}
It is possible to have options that take more than one argument. Simply annotate the method that accepts several Strings.
For example:
@Option(name = "d")
public void setDates(final String firstDate, final String secondDate) {
...
}
To actually process the command line arguments, simply execute the process() method from withon your main method like this:
CommandLineProcessor.process(commandLineObject, args);
The commandLineObject must be an object of a class with the aforementioned annotations.Modifier and Type | Method and Description |
---|---|
static void |
process(Object commandLineObject,
String[] commandLineArguments)
Processes the supplied commandLineArguments and stores the processed information in the supplied commandLineObject.
|
public static void process(Object commandLineObject, String[] commandLineArguments)
commandLineObject
- The Object which methods will be called when arguments are processed.commandLineArguments
- The command line arguments.
NullPointerException
- When either the supplied commandLineObject or commandLineArguments is null.Copyright © 2008–2018. All rights reserved.