@Retention(value=RUNTIME)
@Target(value={PARAMETER,FIELD})
public @interface Required
Indicate a command argument is mandatory
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
errorTemplate
Specify the error message template when it failed to resolve option value to the required argument.
|
java.lang.String |
group
Specify the mutual exclusive group.
|
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 Account showAccount( @Required({“-i”, “–id”}) String id) { return Account.findById(id); }Developer can also use one string separated by “,” to specify two leads:
@Command(“account.show”) public Account showAccount( @Required(“-i,–id”) String id) { return Account.findById(id); }
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 group
Specify the mutual exclusive group. If there are multiple @Required
options found in the command line with the same group then one and only one of them needs to be provided. If more than one argument is provided then the application may choose anyone of the argument. E.g.
@Command("account.show")
public Account showAccount(
@Required(lead = "-i, --id", group = "id") String id,
@Required(lead = "-e, --email", group = "id") String email
) {
if (null != id) {
return Account.findById(id);
} else {
return Account.findByEmail(id);
}
}
In the above command, either id
or email
must be provided, otherwise the framework will throw out IllegalArgumentException
before calling into the method
If not specified, then the marked argument must be provided
public abstract java.lang.String value
Alias of help()
Copyright © 2014–2017 ActFramework. All rights reserved.