public final class CommandLine extends Object
OptionProcessor
s
and declarative options
.Modifier and Type | Method and Description |
---|---|
static CommandLine |
create(Class<?>... classes)
Creates new command line processor based on options defined in
the provided
classes . |
static CommandLine |
create(Object... instances)
Creates new command line processor based on options defined in
the provided
objects . |
static CommandLine |
getDefault()
Getter for the default command line processor in the system.
|
void |
process(String... args)
Process the array of arguments and invoke associated
OptionProcessor s. |
void |
process(String[] args,
InputStream is,
OutputStream os,
OutputStream err,
File currentDir)
Process the array of arguments and invoke associated
OptionProcessor s. |
void |
usage(PrintWriter w)
Prints the usage information about options provided by associated
OptionProcessor s. |
public static CommandLine getDefault()
OptionProcessor
s is taken from default
Lookup.getDefault()
.public static CommandLine create(Class<?>... classes)
classes
. These classes are scanned for
fields annotated with @
Arg
annotation or (since version 2.37) checked whether they implement
@OptionProcessor
.classes
- classes that declare the optionspublic static CommandLine create(Object... instances)
objects
. The objects can implement
the processor
interface or (if they don't) their classes are scanned
for fields annotated with @
Arg
annotation. Alternatively one can register Class
instances with
default constructor - such classes will be instantiated and then
processed as described above.instances
- objects that declare the command line optionspublic void process(String... args) throws CommandException
OptionProcessor
s.args
- the array of strings to processCommandException
- if processing is not possible or failedpublic void process(String[] args, InputStream is, OutputStream os, OutputStream err, File currentDir) throws CommandException
OptionProcessor
s.args
- the array of strings to processis
- the input stream that processors can reados
- the output stream that processors can write toerr
- the output stream that processors can send error messages tocurrentDir
- directory that processors should use as current user dirCommandException
- if processing is not possible or failedpublic void usage(PrintWriter w)
OptionProcessor
s.w
- the writer to output usage info to