|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Retention(value=RUNTIME)
@Documented
@Target(value={FIELD,METHOD})
public @interface CliOption
A CliOption is used to annotate a property (member variable of some
class or setter-method) that should be set from a main-program via a
commandline option.
If the annotated property is a Field it may NOT be
static or
final and by convention it should be
private. Setters may NOT be
static and by convention they
should be public.
The annotated property should be initialized properly at construction in
order to determine whether the option was triggered or not. For non-primitive
types the property should be initialized with null.
When the main-program is invoked an CliOption can be triggered via
its name or one of its aliases. Options
with a type other than boolean need to be followed by a value as
CLI parameter. This value has to be quoted in the commandline if it contains
whitespaces or other characters that are interpreted by the shell (e.g.
backslash in Unix).
The type of the annotated property has to be supported by the CLI
implementation so the value can be converted properly. The following types
are guaranteed to be supported:
| Type | Comment |
|---|---|
String |
The given text as is. |
| boolean | Set to true if CliOption is present. Should be
initialized with false at construction. |
Boolean |
If the option is present with a value of true or
false the according Boolean is applied. Otherwise values
are treated as invalid. According to CliStyle, true may
be omitted. |
Number |
The subclasses of Number from the package java.lang
are always supported. |
File |
A file created from the value of the
option. |
Enum |
A concrete subclass of Enum. The value
needs to match the Enum.name() but case is ignored and underscores
may also be replaced by hyphen ("-") or whitespace (" "). |
ComposedValueConverter
| Required Element Summary | |
|---|---|
String |
name
The actual option (e.g. |
String |
usage
The description of this option for help usage. |
| Optional Element Summary | |
|---|---|
String[] |
aliases
The list of optional aliases that can be used instead of the name(). |
CliContainerStyle |
containerStyle
The style of this option if it has a container
type. |
String |
mode
The ID of the mode. |
String |
operand
The name of the operand for the usage. |
boolean |
required
The flag that indicates if this option is required. |
| Element Detail |
|---|
public abstract String name
public abstract String usage
help usage. It should be an
internationalized message that will be localized using
NlsMessage.
NLS-arguments are "operand" for the localized operand
and "default" for the default value.
public abstract String operand
usage. A CliOption
can either be a switch (if type of annotated field is boolean/Boolean) or
it takes an operand (e.g. "--delay 5"). The name of this operand for the
usage output can be configured here.
public abstract String[] aliases
name(). E.g. for name() "--help" an alias could be "-h".
public abstract boolean required
true to make this option required within it's mode.
CliMode.parentIds()public abstract String mode
ID of the mode. A typical
main-program has different modes how it can be invoked.options of a program can be split into groups that
represent such mode. The options are ordered by their mode in the
help-usage-output and modes allow to express that an option is required only in a specific mode.Options can only be combined as command-line arguments if
their modes are compatible. This means that the modes have
to be identical or one mode extends the other.
In the latter case the most special mode is triggered. For each
mode that is used in an CLI annotated
class an according CliMode annotation has to be present in order
to define the mode.
CliModepublic abstract CliContainerStyle containerStyle
style of this option if it has a container
type. The default is CliContainerStyle.DEFAULT.
CliStyle.containerStyle()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||