public class CommandLineParser
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
CommandLineParser.ClpEnum |
protected static class |
CommandLineParser.OptionDefinition |
protected static class |
CommandLineParser.OptionDefinitionByPrintOrderComparator |
Modifier and Type | Field and Description |
---|---|
java.io.File |
IGNORE_THIS_PROPERTY
This attribute is here just to facilitate printing usage for OPTIONS_FILE
|
Constructor and Description |
---|
CommandLineParser(java.lang.Object callerOptions)
Prepare for parsing command line arguments, by validating annotations.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
getArgv() |
java.lang.Object |
getCallerOptions() |
java.lang.String |
getCommandLine()
The commandline used to run this program, including any default args that
weren't necessarily specified.
|
static java.lang.String |
getFaqLink() |
static java.lang.String |
getStandardUsagePreamble(java.lang.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."
|
java.lang.String |
getVersion() |
static boolean |
hasWebDocumentation(java.lang.Class clazz)
Determines if a class has web documentation based on its package name
|
void |
htmlPrintOptions(java.io.PrintStream stream,
boolean printCommon) |
void |
htmlUsage(java.io.PrintStream stream,
java.lang.String programName,
boolean printCommon) |
boolean |
parseOptions(java.io.PrintStream messageStream,
java.lang.String[] args)
Parse command-line options, and store values in callerOptions object passed to ctor.
|
boolean |
parseOptionsFile(java.lang.String optionsFile,
boolean optionFileStyleValidation) |
void |
setMessageStream(java.io.PrintStream messageStream)
This method is only needed when calling one of the public methods that doesn't take a messageStream argument.
|
void |
usage(java.io.PrintStream stream,
boolean printCommon)
Print a usage message based on the options object passed to the ctor.
|
public java.io.File IGNORE_THIS_PROPERTY
public CommandLineParser(java.lang.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 java.lang.String getStandardUsagePreamble(java.lang.Class mainClass)
public static boolean hasWebDocumentation(java.lang.Class clazz)
clazz
- public static java.lang.String getFaqLink()
public java.lang.String getVersion()
public void usage(java.io.PrintStream stream, boolean printCommon)
stream
- Where to write the usage message.public void htmlUsage(java.io.PrintStream stream, java.lang.String programName, boolean printCommon)
public void htmlPrintOptions(java.io.PrintStream stream, boolean printCommon)
public boolean parseOptions(java.io.PrintStream messageStream, java.lang.String[] args)
messageStream
- Where to write error messages.args
- Command line tokens.public boolean parseOptionsFile(java.lang.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 java.lang.String[] getArgv()
public java.lang.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(java.io.PrintStream messageStream)
public java.lang.Object getCallerOptions()