Repository navigation
Expand file tree
/
Copy pathRequired.java
More file actions
75 lines (68 loc) · 2.65 KB
/
Copy pathRequired.java
File metadata and controls
75 lines (68 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package act.cli;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicate a command argument is mandatory
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.PARAMETER, ElementType.FIELD})
public @interface Required {
/**
* Specify the argument lead, e.g.
* <pre>
* {@literal @}Command("account.show")
* public Account showAccount({@literal @}Required({"-i", "--id"}) String id) {
* return Account.findById(id);
* }
* </pre>
* Developer can also use one string separated by "," to specify two leads:
* <pre>
* {@literal @}Command("account.show")
* public Account showAccount({@literal @}Required("-i,--id") String id) {
* return Account.findById(id);
* }
* </pre>
* <p>If not specified, then the system will assume the argument lead to be follows</p>
* <ul>
* <li>{@code -o}, where "o" is the first char of the argument name</li>
* <li>{@code --option}, where "option" is the full argument name</li>
* </ul>
* @return the argument lead as described
*/
String[] lead() default "";
/**
* Specify the mutual exclusive group. If there are multiple {@code @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.
* <pre>
* {@literal @}Command("account.show")
* public Account showAccount({@literal @}Required(value = {"-i", "--id"}, group = "id") String id,
* {@literal @}Required(value = "-e, --email", group = "id") String email) {
* if (null != id) {
* return Account.findById(id);
* } else {
* return Account.findByEmail(id);
* }
* }
* </pre>
* <p>In the above command, either {@code id} or {@code email} must be provided, otherwise
* the framework will throw out {@code IllegalArgumentException}
* before calling into the method</p>
* <p>If not specified, then the marked argument must be provided in regarding to other
* arguments</p>
* @return the mutual exclusive group
*/
String group() default "";
/**
* Alias of {@link #help()}
* @return the help message
*/
String value() default "";
/**
* Specify the help message for this option
* @return the help message
*/
String help() default "";
}