public class CommandLineParser extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
CommandLineParser.ClpEnum |
protected static class |
CommandLineParser.OptionDefinition |
Modifier and Type | Field and Description |
---|---|
File |
IGNORE_THIS_PROPERTY
This attribute is here just to facilitate printing usage for OPTIONS_FILE
|
Constructor and Description |
---|
CommandLineParser(Object callerOptions)
Prepare for parsing command line arguments, by validating annotations.
|
Modifier and Type | Method and Description |
---|---|
String[] |
getArgv() |
Object |
getCallerOptions() |
String |
getCommandLine()
The commandline used to run this program, including any default args that
weren't necessarily specified.
|
static String |
getFaqLink() |
static String |
getStandardUsagePreamble(Class mainClass)
A typical command line program will call this to get the beginning of the usage message,
and then append a description of the program, like this:
\@Usage
public String USAGE = CommandLineParser.getStandardUsagePreamble(getClass()) + "Frobnicates the freebozzle."
|
String |
getVersion() |
static boolean |
hasWebDocumentation(Class clazz)
Determines if a class has web documentation based on its package name
|
void |
htmlPrintOptions(PrintStream stream,
boolean printCommon) |
void |
htmlUsage(PrintStream stream,
String programName,
boolean printCommon) |
boolean |
parseOptions(PrintStream messageStream,
String[] args)
Parse command-line options, and store values in callerOptions object passed to ctor.
|
boolean |
parseOptionsFile(String optionsFile,
boolean optionFileStyleValidation) |
void |
setMessageStream(PrintStream messageStream)
This method is only needed when calling one of the public methods that doesn't take a messageStream argument.
|
void |
usage(PrintStream stream,
boolean printCommon)
Print a usage message based on the options object passed to the ctor.
|
public File IGNORE_THIS_PROPERTY
public CommandLineParser(Object callerOptions)
callerOptions
- This object contains annotations that define the acceptable command-line options,
and ultimately will receive the settings when a command line is parsed.public static String getStandardUsagePreamble(Class mainClass)
public static boolean hasWebDocumentation(Class clazz)
clazz
- public static String getFaqLink()
public String getVersion()
public void usage(PrintStream stream, boolean printCommon)
stream
- Where to write the usage message.public void htmlUsage(PrintStream stream, String programName, boolean printCommon)
public void htmlPrintOptions(PrintStream stream, boolean printCommon)
public boolean parseOptions(PrintStream messageStream, String[] args)
messageStream
- Where to write error messages.args
- Command line tokens.public boolean parseOptionsFile(String optionsFile, boolean optionFileStyleValidation)
optionFileStyleValidation
- true: unrecognized options are silently ignored; and a single-valued option may be overridden.
false: standard rules as if the options in the file were on the command line directly.public String[] getArgv()
public String getCommandLine()
parseOptions(PrintStream, String[])
must be called before
calling this method.parseOptions(PrintStream, String[])
hasn't yet been called, or didn't complete successfully.public void setMessageStream(PrintStream messageStream)
public Object getCallerOptions()