For typical usage, see this example.
| Modifier and Type | Class and Description |
|---|---|
| private class | CmdLineParser.
Essentially a pointer over a |
| Modifier and Type | Field and Description |
|---|---|
| private final List | arguments
Discovered |
| private OptionHandler | |
| private final List | options
Discovered |
| private ParserProperties | parserProperties
settings for the parser |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | CmdLineParser(Object bean)
Creates a new command line owner that parses arguments/options and set them into the given object. |
| public | CmdLineParser(Object bean, ParserProperties
various settings for this class parserProperties)Creates a new command line owner that parses arguments/options and set them into the given object. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addArgument(Setter<T>
the setter for the type setter, Argument the Argument a)Programmatically defines an argument (instead of reading it from annotations as normal). |
| public void | |
| private void | |
| private void | |
| private String | |
| protected OptionHandler | createOptionHandler(OptionDef o, Setter<T> setter)
Creates an |
| private String[] | Returns: args with the @ sequences replaced by the text files referenced by the @ sequences, split around the line breaks.the command line arguments to be preprocessed. args)Expands every entry prefixed with the AT sign by reading the file. |
| private OptionHandler | Returns: theOptionHandler or nullname name)Finds a registered |
| private OptionHandler | |
| public List | |
| private String | |
| public List | |
| private int | |
| public ParserProperties | |
| private boolean | Returns: true if all options forbid by option are not present, false otherwise
|
| private boolean | Returns: true if all options required by option are present, false otherwise
|
| protected boolean | |
| private String | |
| public void | |
| public void | parseArgument(final String...
arguments to parse args)Parses the command line arguments and set them to the option bean given in the constructor. |
| public String | Returns: always non-null.must not be filter)null.Formats a command line example into a string. |
| public String | |
| public String | Returns: always non-null. If there's no option, this method returns
just the empty string "". Otherwise, this method returns a
string that contains a space at the beginning (but not at the end).
This allows you to do something like:
System.err.println("java -jar my.jar"+parser.printExample(REQUIRED)+" arg1 arg2");Determines which options will be a part of the returned string.
Must not be mode, ResourceBundle null.If non- rb)null, meta variables (<dir> in the above example)
is treated as a key to this resource bundle, and the associated
value is printed. See Option#metaVar(). This is to support
localization.
Passing null would print Option#metaVar() directly.Formats a command line example into a string. |
| public String | printExample(ExampleMode mode, ResourceBundle rb)
Deprecated
Use
printExample(OptionHandlerFilter, ResourceBundle)
|
| protected void | printOption(PrintWriter
Writer to write into out, OptionHandler<T> handler where to receive the information handler, int Maximum length of metadata column len, ResourceBundle ResourceBundle for I18NPrints usage information for a given option. |
| private void | |
| public void | |
| public void | printSingleLineUsage(Writer w, ResourceBundle
if this is non- rb)null, Option#usage() is treated
as a key to obtain the actual message from this resource bundle.Prints a single-line usage to the screen. |
| public void | |
| public void | printUsage(Writer out, ResourceBundle rb)
Prints the list of all the non-hidden options and their usages to the screen. |
| public void | printUsage(Writer out, ResourceBundle
If non- rb, OptionHandlerFilter null, Option#usage() is treated
as a key to obtain the actual message from this resource bundle.Controls which options to be printed. filter)Prints the list of all the non-hidden options and their usages to the screen. |
| private static List | |
| public static void | registerHandler(Class<T>
The specified handler is used when the field/method annotated by valueType, Class<? extends OptionHandler<T>> Option
is of this type.This class must have the constructor that has the same signature as
handlerClass)OptionHandler#OptionHandler(CmdLineParser, OptionDef, Setter)
Deprecated
You should use
OptionHandlerRegistry#registerHandler(java. instead.
Registers a user-defined |
| public void | setUsageWidth(int
the width of the usage output in columns. usageWidth)
Deprecated
Use
ParserProperties#withUsageWidth(int) instead.
Sets the width of the usage output. |
| public void | |
| private List |
| arguments | back to summary |
|---|---|
| private final List<OptionHandler<T>> arguments Discovered | |
| currentOptionHandler | back to summary |
|---|---|
| private OptionHandler<T> currentOptionHandler | |
| options | back to summary |
|---|---|
| private final List<OptionHandler<T>> options Discovered | |
| parserProperties | back to summary |
|---|---|
| private ParserProperties parserProperties settings for the parser | |
| parsingOptions | back to summary |
|---|---|
| private boolean parsingOptions | |
| CmdLineParser | back to summary |
|---|---|
| public CmdLineParser(Object bean) Creates a new command line owner that parses arguments/options and set them into the given object.
| |
| CmdLineParser | back to summary |
|---|---|
| public CmdLineParser(Object bean, ParserProperties parserProperties) Creates a new command line owner that parses arguments/options and set them into the given object.
| |
| addArgument | back to summary |
|---|---|
| public void addArgument(Setter<T> setter, Argument a) Programmatically defines an argument (instead of reading it from annotations as normal).
| |
| addOption | back to summary |
|---|---|
| public void addOption(Setter<T> setter, Option o) Programmatically defines an option (instead of reading it from annotations as normal).
| |
| checkOptionNotInMap | back to summary |
|---|---|
| private void checkOptionNotInMap(String name) throws IllegalAnnotationError | |
| checkRequiredOptionsAndArguments | back to summary |
|---|---|
| private void checkRequiredOptionsAndArguments(Set<OptionHandler<T>> present) throws CmdLineException | |
| createDefaultValuePart | back to summary |
|---|---|
| private String createDefaultValuePart(OptionHandler<T> handler) | |
| createOptionHandler | back to summary |
|---|---|
| protected OptionHandler Creates an | |
| expandAtFiles | back to summary |
|---|---|
| private String[] expandAtFiles(String[] args) throws CmdLineException Expands every entry prefixed with the AT sign by reading the file. The AT sign is used to reference another file that contains command line options separated by line breaks. | |
| findOptionByName | back to summary |
|---|---|
| private OptionHandler Finds a registered
| |
| findOptionHandler | back to summary |
|---|---|
| private OptionHandler | |
| getArguments | back to summary |
|---|---|
| public List Lists up all the defined arguments in the order. | |
| getOptionName | back to summary |
|---|---|
| private String getOptionName() | |
| getOptions | back to summary |
|---|---|
| public List Lists up all the defined options. | |
| getPrefixLen | back to summary |
|---|---|
| private int getPrefixLen(OptionHandler<T> h, ResourceBundle rb) | |
| getProperties | back to summary |
|---|---|
| public ParserProperties getProperties() | |
| isHandlerAllowOtherOptions | back to summary |
|---|---|
private boolean isHandlerAllowOtherOptions(NamedOptionDef option, Set<OptionHandler<T>> present)
| |
| isHandlerHasHisOptions | back to summary |
|---|---|
private boolean isHandlerHasHisOptions(NamedOptionDef option, Set<OptionHandler<T>> present)
| |
| isOption | back to summary |
|---|---|
| protected boolean isOption(String arg) Returns
| |
| localize | back to summary |
|---|---|
| private String localize(String s, ResourceBundle rb) | |
| parseArgument | back to summary |
|---|---|
| public void parseArgument(Collection<String> args) throws CmdLineException Same as | |
| parseArgument | back to summary |
|---|---|
| public void parseArgument(final String... args) throws CmdLineException Parses the command line arguments and set them to the option bean given in the constructor.
| |
| printExample | back to summary |
|---|---|
| public String printExample(OptionHandlerFilter filter) Formats a command line example into a string.
See
| |
| printExample | back to summary |
|---|---|
| public String printExample(ExampleMode mode)
Deprecated | |
| printExample | back to summary |
|---|---|
| public String printExample(OptionHandlerFilter mode, ResourceBundle rb) Formats a command line example into a string.
This method produces a string like
| |
| printExample | back to summary |
|---|---|
| public String printExample(ExampleMode mode, ResourceBundle rb)
Deprecated | |
| printOption | back to summary |
|---|---|
| protected void printOption(PrintWriter out, OptionHandler<T> handler, int len, ResourceBundle rb, OptionHandlerFilter filter) Prints usage information for a given option.
Subtypes may override this method and determine which options get printed (or other things),
based on
| |
| printSingleLineOption | back to summary |
|---|---|
| private void printSingleLineOption(PrintWriter pw, OptionHandler<T> h, ResourceBundle rb) | |
| printSingleLineUsage | back to summary |
|---|---|
| public void printSingleLineUsage(OutputStream out) Prints a single-line usage to the screen.
This is a convenience method for calling
| |
| printSingleLineUsage | back to summary |
|---|---|
| public void printSingleLineUsage(Writer w, ResourceBundle rb) Prints a single-line usage to the screen.
| |
| printUsage | back to summary |
|---|---|
| public void printUsage(OutputStream out) Prints the list of options and their usages to the screen.
This is a convenience method for calling | |
| printUsage | back to summary |
|---|---|
| public void printUsage(Writer out, ResourceBundle rb) Prints the list of all the non-hidden options and their usages to the screen.
Short for | |
| printUsage | back to summary |
|---|---|
| public void printUsage(Writer out, ResourceBundle rb, OptionHandlerFilter filter) Prints the list of all the non-hidden options and their usages to the screen.
| |
| readAllLines | back to summary |
|---|---|
| private static List Reads all lines of a file with the platform encoding. | |
| registerHandler | back to summary |
|---|---|
| public static void registerHandler(Class<T> valueType, Class<? extends OptionHandler<T>> handlerClass)
Deprecated You should use Registers a user-defined
This method allows users to extend the behavior of args4j by writing
their own
| |
| setUsageWidth | back to summary |
|---|---|
| public void setUsageWidth(int usageWidth)
Deprecated Use Sets the width of the usage output.
| |
| stopOptionParsing | back to summary |
|---|---|
| public void stopOptionParsing() Signals the parser that parsing the options has finished. Everything seen after this call is treated as an argument as opposed to an option. | |
| wrapLines | back to summary |
|---|---|
| private List Wraps a line so that the resulting parts are not longer than a given maximum length. | |
String array.
Can move forward; can look ahead.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected String | |
| public String | getParameter(int
specifying 0 will retrieve the token next to the option.
For example, if the command line looks like idx)-o abc -d x,
then getParameter(0) for -o returns abc
and getParameter(1) will return -d.Implements org. Gets the additional parameter to this option. |
| protected boolean | |
| private void | |
| public int | |
| pack-priv void | splitToken()
Used when the current token is of the form "-option=value", to replace the current token by "value", as if this was given as two tokens "-option value" |
| CmdLineImpl | back to summary |
|---|---|
| pack-priv CmdLineImpl(String[] args) | |
| getCurrentToken | back to summary |
|---|---|
| protected String getCurrentToken() | |
| getParameter | back to summary |
|---|---|
| public String getParameter(int idx) throws CmdLineException Implements org. Doc from org. Gets the additional parameter to this option.
| |
| hasMore | back to summary |
|---|---|
| protected boolean hasMore() | |
| proceed | back to summary |
|---|---|
| private void proceed(int n) | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Number of remaining tokens. | |
| splitToken | back to summary |
|---|---|
| pack-priv void splitToken() Used when the current token is of the form "-option=value", to replace the current token by "value", as if this was given as two tokens "-option value" | |