@Retention(value=RUNTIME)
@Target(value={PARAMETER,FIELD})
public @interface Optional
Indicate a command argument is optional
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
defVal
Specify the default value in String.
|
java.lang.String |
errorTemplate
Specify the error message template when it failed to resolve option value to the required argument.
|
java.lang.String |
help
Specify the help message for this option
|
java.lang.String[] |
lead
Specify the argument lead, e.g.
|
java.lang.String |
value
Alias of
help() |
public abstract java.lang.String[] lead
Specify the argument lead, e.g.
@Command("account.show")
public List<Account> listAccount(
@Optional({"-q", "--query"}) String q,
@Optional(value = "-l, --limit", defVal = "-1") int limit
) {
Query query = new Query();
if (null != q) {
query.filter("text", q);
}
if (limit > -1) {
query.limit(limit);
}
return Account.find(query).asList();
}
If not specified, then the system will assume the argument lead to be follows
-o
, where “o” is the first char of the argument name--option
, where “option” is the full argument namepublic abstract java.lang.String defVal
Specify the default value in String. The framework will automatically convert the String to required type (all primitive types and their correlated classes, String, and Enum types).
value()
public abstract java.lang.String value
Alias of help()
Copyright © 2014–2017 ActFramework. All rights reserved.