|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object be.ugent.twijug.jclops.CLManager
public class CLManager
Command line manager. Processes command line options by calling the appropriate (setter) methods in a secondary object, called an option context. The option context class (optionally) contains annotations which configure option names and behaviour.
To process command line options, take the following steps:
CLManager()
.registerArgumentParser(be.ugent.twijug.jclops.ArgumentParser, java.lang.Class)
.
Argument parsers
are responsible for converting the command line option arguments to objects
of the correct type for the corresponding setter methods. By default, we provide
argument parsers
for all primitive types and their wrapper classes, for String
and for all enum
classes.setContext(java.lang.Object)
.
This will configure the options, and in case of errors a
CLDefinitionException
will be thrown.parse(java.lang.String[])
.
If a parsing error occurs, an exception of type CLParseException
will be thrown.
getRemainingArguments()
.CLManager(Object)
.
The command line manager also automatically generates a 'usage message' which
can be obtained from getUsageMessage()
.
ArgumentParser
Constructor Summary | |
---|---|
CLManager()
Create a new command line manager. |
|
CLManager(java.lang.Object context)
Create a new command line manager for the given option context. |
Method Summary | ||
---|---|---|
java.lang.String[] |
getRemainingArguments()
The command line arguments that remain after all options are processed |
|
java.lang.String |
getUsageMessage()
Generate the usage message from the current option context. |
|
void |
parse(java.lang.String[] args)
Parses the given command line arguments. |
|
|
registerArgumentParser(ArgumentParser<T> parser,
java.lang.Class<T> type)
Install an option argument parser for a specific type. |
|
void |
setContext(java.lang.Object context)
Register the option context object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CLManager(java.lang.Object context)
Note: if any argument parsers are needed other than
those that are provided by default, you must instead use the default constructor,
register the argument parsers and then apply setContext(java.lang.Object)
.
context
- Option context object
CLDefinitionException
- when there is a configuration errorpublic CLManager()
parse(java.lang.String[])
is called, but after all argument parsers are
registered with registerArgumentParser(be.ugent.twijug.jclops.ArgumentParser, java.lang.Class)
.
Method Detail |
---|
public void setContext(java.lang.Object context)
CLDefinitionException
- when there is a configuration errorpublic void parse(java.lang.String[] args)
args
- Array of command line arguments to be parsed
CLParseException
- when an error occurred during parsing, i.e.,
when the user provided a command line which was invalid in some waypublic java.lang.String[] getRemainingArguments()
public java.lang.String getUsageMessage()
public <T> void registerArgumentParser(ArgumentParser<T> parser, java.lang.Class<T> type)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |