@Retention(RUNTIME) @Target(FIELD) public @interface Arg
Description
which provides
human readable explanation of the option's behavior. The field should be
public and the class should have public default constructor. It is suggested
the class implements ArgsProcessor
or at least Runnable
- its
methods will be called after successful assignment of argument fields. Here
is an example:
public final class YourOptions implementsArgsProcessor
{ // Defines an option without any arguments public@
Arg
(shortName='p', longName="") public boolean usedWithO; // if such option is present on the command line, the value of the //usedWithO
field is set totrue
. Otherwise its // value remains unchanged (e.g.false
). // One can also annotate aString
field which then becomes // an option with arequired argument
: public@
Arg
(shortName='r', longName="") public String requiredArg; // If one annotates a field where an array ofstrings
can be // assigned, such option will then contain all //additional arguments
// made available: public@
Arg
(longName="additional") public String[] additionalArgs; // To define an option withoptional argument
// one can annotate string field and provide its default value:@
Arg
(shortName='o', longName="", defaultValue="used-but-no-argument-provided") public String optionArg; public void process(Env
env) { // when this method is called, above defined fields are initialized } }
Modifier and Type | Required Element | Description |
---|---|---|
String |
longName |
Multi character name.
|
Modifier and Type | Optional Element | Description |
---|---|---|
String |
defaultValue |
Some fields may require no argument and still be present.
|
boolean |
implicit |
Specifies whether this field should be implicit/
default . |
char |
shortName |
One character name of the option.
|
String longName
""
to assign no long name to the option.char shortName
boolean implicit
default
.
There may be only one implicit option in the system. If there are
arguments not consumed by any other option, they are passed to it.
The implicit options may annotate only fields of type String[]
.String defaultValue
Built on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.