1
2
3
4
5
6
7
8
9
10
11
12 package gov.nasa.pds.tools.options;
13
14 import org.apache.commons.cli.Option;
15
16 /***
17 * Class that extends Apache's Option class. Provides a simpler interface to build command-line
18 * option flags.
19 *
20 *
21 * @author mcayanan
22 *
23 */
24 public class ToolsOption extends Option {
25
26 private final char argSeparator = ',';
27
28 /***
29 * Contstructor.
30 *
31 * @param opt Short name of the option.
32 * @param longOpt Long name of the option. Can be set to 'null'.
33 * @param description Description of the option.
34 */
35 public ToolsOption(String opt, String longOpt, String description) {
36 super(opt, longOpt, false, description);
37 }
38
39 /***
40 * Requires a single argument to follow the option.
41 *
42 * @param name Sets the display name of the argument value.
43 * @param type Sets the data type allowed for this argument.
44 */
45 public void hasArg(String name, Object type) {
46 hasArg(name, type, false);
47 }
48
49 /***
50 * Allows a single argument to be passed into the option.
51 *
52 * @param name Sets the display name of the argument value.
53 * @param type Sets the data type allowed for this argument.
54 * @param isOptional Set to 'true' if the argument is optional, 'false' otherwise.
55 */
56 public void hasArg(String name, Object type, boolean isOptional) {
57 char nullChar = '\0';
58 hasArgs(1, name, type, nullChar, isOptional);
59 }
60
61 /***
62 * Requires an argument to follow the option. This method allows the option
63 * to take in multiple arguments. Does not define a maximum
64 * number of allowable arguments.
65 *
66 * The separator value is set to the space character ' '.
67 *
68 * @param name Sets the display name of the argument value.
69 * @param type Sets the data type allowed for this argument.
70 */
71 public void hasArgs(String name, Object type) {
72 hasArgs(name, type, argSeparator, false);
73 }
74
75 /***
76 * Requires an argument to follow the option. Allows multiple arguments
77 * to be passed in to the option. Does not define a maximum number of
78 * allowable arguments.
79 *
80 *
81 * @param name Sets the display name of the argument value.
82 * @param type Sets the data type allowed for this argument.
83 * @param separator Sets the separator value allowed in between the
84 * argument values being passed in.
85 */
86 public void hasArgs(String name, Object type, char separator) {
87 hasArgs(name, type, separator, false);
88 }
89
90 /***
91 * Allows multiple arguments to be passed in to the option. Does not
92 * define a maximum number of allowable arguments.
93 *
94 * @param name Sets the display name of the argument value.
95 * @param type Sets the data type allowed for this argument.
96 * @param separator Sets the separator value allowed in between the
97 * argument values being passed in.
98 * @param isOptional Set to 'true' if an argument is optional,
99 * 'false' otherwise.
100 */
101 public void hasArgs(String name, Object type, char separator, boolean isOptional) {
102 hasArgs(Option.UNLIMITED_VALUES, name, type, separator, isOptional);
103 }
104
105 /***
106 * Defines an argument's "properties" for an option.
107 *
108 * @param numArgs Max number of arguments allowed.
109 * @param name Sets the display name of the argument value.
110 * @param type Sets the data type allowed for this argument.
111 * @param separator Sets the separator value allowed in between the
112 * argument values being passed in.
113 * @param isOptional Set to 'true' if an argument is optional, 'false'
114 * otherwise.
115 */
116 public void hasArgs(int numArgs, String name, Object type, char separator, boolean isOptional) {
117 setArgs(numArgs);
118 setArgName(name);
119 setType(type);
120 setValueSeparator(separator);
121 setOptionalArg(isOptional);
122 }
123
124 }