| java.lang.Object org.kohsuke.args4j.CmdLineParser
CmdLineParser | public class CmdLineParser (Code) | | Command line argument owner.
For a typical usage, see this example.
author: Kohsuke Kawaguchi (kk@kohsuke.org) |
Constructor Summary | |
public | CmdLineParser(Object bean) Creates a new command line owner that
parses arguments/options and set them into
the given object. |
CmdLineParser | public CmdLineParser(Object bean)(Code) | | Creates a new command line owner that
parses arguments/options and set them into
the given object.
Parameters: bean - instance of a class annotated by Option and Argument.this object will receive values. throws: IllegalAnnotationError - if the option bean class is using args4j annotations incorrectly. |
isOption | protected boolean isOption(String arg)(Code) | | Returns true if the given token is an option
(as opposed to an argument.)
|
parseArgument | public void parseArgument(String... args) throws CmdLineException(Code) | | Parses the command line arguments and set them to the option bean
given in the constructor.
Parameters: args - arguments to parse throws: CmdLineException - if there's any error parsing arguments, or ifOption.required required option was not given. |
printExample | public String printExample(ExampleMode mode, ResourceBundle rb)(Code) | | Formats a command line example into a string.
This method produces a string like " -d <dir> -v -b",
which is useful for printing a command line example, perhaps
as a part of the usage screen.
Parameters: mode - One of the ExampleMode constants. Must not be null.This determines what option should be a part of the returned string. Parameters: rb - If non-null, meta variables (<dir> in the above example)is treated as a key to this resource bundle, and the associatedvalue is printed. See Option.metaVar. This is to supportlocalization.Passing null would print Option.metaVar directly.always non-null. If there's no option, this method returnsjust the empty string "". Otherwise, this method returns astring 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"); |
printSingleLineUsage | public void printSingleLineUsage(OutputStream out)(Code) | | Prints a single-line usage to the screen.
This is a convenience method for calling
printUsage(new OutputStreamWriter(out),null) so that you can do
printUsage(System.err) .
|
printSingleLineUsage | public void printSingleLineUsage(Writer w, ResourceBundle rb)(Code) | | Prints a single-line usage to the screen.
Parameters: rb - if this is non-null, Option.usage is treatedas a key to obtain the actual message from this resource bundle. |
printUsage | public void printUsage(OutputStream out)(Code) | | Prints the list of options and their usages to the screen.
This is a convenience method for calling
printUsage(new OutputStreamWriter(out),null) so that you can do
printUsage(System.err) .
|
printUsage | public void printUsage(Writer out, ResourceBundle rb)(Code) | | Prints the list of options and their usages to the screen.
Parameters: rb - if this is non-null, Option.usage is treatedas a key to obtain the actual message from this resource bundle. |
setUsageWidth | public void setUsageWidth(int usageWidth)(Code) | | |
stopOptionParsing | public void stopOptionParsing()(Code) | | |
|
|