@Retention(value=RUNTIME) @Target(value=FIELD) public @interface CommandLineOption
All elements are optional. Thus the simplest usage is:
@CommandLineOptionThe above will match the option
private Boolean verbose;
--verbose when parsing
(JArgP.parse(java.lang.String[])), and if it is present, the field
verbose (of the "subject", see
JArgP.JArgP(java.lang.Object)) will be set to
true.
If you want the command line option to use the next argument as a value for a
field, make the field something other than a Boolean. Values are
converted in Option.convert(java.lang.String, java.lang.Class), see
its documentation for details.
To configure the specifics of the command line option and how it is parsed, see each element:
names()
and pattern().JArgP.printUsage(java.io.PrintStream)), see
placeholder(), description(), defaultValue() and
defaultValue().JArgP| Modifier and Type | Optional Element and Description |
|---|---|
String |
defaultValue
A default value.
|
String |
description
A description of the option to use for the usage text.
|
String[] |
names
The names of the option.
|
boolean |
opposite
Creates a
--no-[...] alias that sets it to
false. |
String |
pattern
For complex names match this pattern.
|
String |
placeholder
Text to use as a placeholder when printing the usage.
|
String |
setter
Specifies a method to set the value.
|
String |
shortPattern
For complex names match this pattern.
|
public abstract String[] names
If no names are specified (and no pattern() is specified), the
name of the field itself is used.
Single character names will be short options (
-[...]), others will be long options (
--[...]), with the exception of
-, which will be just that.
pattern()public abstract String setter
String
parameters, where the first one is the name and the second one is the
value:
<setter>(or a singleStringname,Stringvalue)
String parameter that is the value:
<setter>(String value)
For multiples (Collections) it is assumed the setter
appends a single value.
One reason to use a setter would be to do some kind of validation of the
value. You may throw an exception in the setter if the value is
considered invalid. E.g. an ArgumentParsingException, but any type
can be used, just make sure to catch it wherever you call
JArgP.parse(java.lang.String[]).
If not used, members will be set directly.
public abstract String pattern
E.g:
[0-9]+ for options like
-1,
-2, etc.
shortPattern(),
names()public abstract String shortPattern
shortPatterns are matched against short options (--[...]). Patterns will be matched
after names and aliases.
E.g:
[0-9]+ for options like
-1,
-2, etc.
pattern()public abstract boolean opposite
--no-[...] alias that sets it to
false.
Switches only.
public abstract String placeholder
E.g. for an option called
file one might set the placeholder to "FILE", to get a usage
like:
--file FILE
The default is "VALUE".
Only used for options that take a value, i.e. not
Booleans.
public abstract String description
public abstract String defaultValue
JArgP.parse(java.lang.String[]) to any member that has not been set
by the arguments.Copyright © 2014 Munkei. All rights reserved.