1 package org.cyclopsgroup.jcli.example;
2
3 import java.util.Date;
4 import java.util.List;
5 import org.cyclopsgroup.caff.conversion.DateField;
6 import org.cyclopsgroup.jcli.ArgumentProcessor;
7 import org.cyclopsgroup.jcli.annotation.Argument;
8 import org.cyclopsgroup.jcli.annotation.Cli;
9 import org.cyclopsgroup.jcli.annotation.MultiValue;
10 import org.cyclopsgroup.jcli.annotation.Option;
11 import com.google.common.base.MoreObjects;
12
13
14
15
16
17
18 @Cli(name = "user", description = "Comamnd line tool that manages user accounts")
19 public class UserControl {
20 private UserControlAction action = UserControlAction.DISPLAY;
21
22 private Date creationDate;
23
24 private int intValue;
25
26 private List<String> userNames;
27
28
29
30
31 @Option(name = "a", longName = "action", description = "Action to perform")
32 public final UserControlAction getAction() {
33 return action;
34 }
35
36
37
38
39 @DateField(format = "yyyyMMdd")
40 @Option(name = "d", longName = "date", description = "Start date")
41 public Date getCreationDate() {
42 return creationDate;
43 }
44
45
46
47
48 @Option(name = "l", longName = "level", description = "A meaningless integer value")
49 public final int getIntValue() {
50 return intValue;
51 }
52
53
54
55
56 @MultiValue
57 @Argument(description = "User account name")
58 public final List<String> getUserNames() {
59 return userNames;
60 }
61
62
63
64
65 public final void setAction(UserControlAction action) {
66 this.action = action;
67 }
68
69
70
71
72 public void setCreationDate(Date creationDate) {
73 this.creationDate = creationDate;
74 }
75
76
77
78
79 public final void setIntValue(int intValue) {
80 this.intValue = intValue;
81 }
82
83
84
85
86 public final void setUserNames(List<String> userNames) {
87 this.userNames = userNames;
88 }
89
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(getClass()).addValue(userNames).addValue(intValue)
93 .addValue(creationDate).toString();
94 }
95
96
97
98
99 public static void main(String[] args) {
100 UserControlControl.html#UserControl">UserControl control = new UserControl();
101 ArgumentProcessor.forType(UserControl.class).process(args, control);
102 System.out.println(control);
103 }
104 }