View Javadoc

1   //Copyright 2007-2008, by the California Institute of Technology.
2   //ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged.
3   //Any commercial use must be negotiated with the Office of Technology Transfer
4   //at the California Institute of Technology.
5   //
6   //This software is subject to U. S. export control laws and regulations
7   //(22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software
8   //is subject to U.S. export control laws and regulations, the recipient has
9   //the responsibility to obtain export licenses or other export authority as
10  //may be required before exporting such information to foreign countries or
11  //providing access to foreign nationals.
12  //
13  // $Id$
14  
15  package gov.nasa.pds.tools.options;
16  
17  import org.apache.commons.cli.Option;
18  
19  /***
20   * Class that extends Apache's Option class. Provides a simpler interface to build command-line
21   * option flags.
22   * 
23   * 
24   * @author mcayanan
25   *
26   */
27  public class ToolsOption extends Option {
28  	
29  	private final char argSeparator = ',';
30  	
31  	/***
32  	 * Constructor.
33  	 * 
34  	 * @param opt Short name of the option.
35  	 * @param longOpt Long name of the option. Can be set to 'null'.
36  	 * @param description Description of the option.
37  	 */
38  	public ToolsOption(String opt, String longOpt, String description) {
39  		super(opt, longOpt, false, description);
40  	}
41  			
42  	/***
43  	 * Requires a single argument to follow the option.
44  	 * 
45  	 * @param name Sets the display name of the argument value.
46  	 * @param type Sets the data type allowed for this argument.
47  	 */
48  	public void hasArg(String name, Object type) {
49  		hasArg(name, type, false);
50  	}
51  	
52  	/***
53  	 * Allows a single argument to be passed into the option. 
54  	 * 
55  	 * @param name Sets the display name of the argument value.
56  	 * @param type Sets the data type allowed for this argument.
57  	 * @param isOptional Set to 'true' if the argument is optional, 'false' otherwise.
58  	 */
59  	public void hasArg(String name, Object type, boolean isOptional) {
60  		char nullChar = '\0';
61  		hasArgs(1, name, type, nullChar, isOptional);
62  	}
63  	
64  	/***
65  	 * Requires an argument to follow the option. This method allows the option
66  	 * to take in multiple arguments. Does not define a maximum
67  	 * number of allowable arguments. 
68  	 * 
69  	 * The separator value is set to the space character ' '. 
70  	 *  
71  	 * @param name Sets the display name of the argument value.
72  	 * @param type Sets the data type allowed for this argument.
73  	 */
74  	public void hasArgs(String name, Object type) {
75  		hasArgs(name, type, argSeparator, false);
76  	}
77  	
78  	/***
79  	 * Requires an argument to follow the option. Allows multiple arguments
80  	 * to be passed in to the option. Does not define a maximum number of
81  	 * allowable arguments. 
82  	 * 
83  	 * 
84  	 * @param name Sets the display name of the argument value.
85  	 * @param type Sets the data type allowed for this argument.
86  	 * @param separator Sets the separator value allowed in between the
87  	 * argument values being passed in.
88  	 */
89  	public void hasArgs(String name, Object type, char separator) {
90  		hasArgs(name, type, separator, false);
91  	}
92  	
93  	/***
94  	 * Allows multiple arguments to be passed in to the option. Does not
95  	 * define a maximum number of allowable arguments.
96  	 * 
97  	 * @param name Sets the display name of the argument value.
98  	 * @param type Sets the data type allowed for this argument.
99  	 * @param separator Sets the separator value allowed in between the
100 	 * argument values being passed in.
101 	 * @param isOptional Set to 'true' if an argument is optional, 
102 	 * 'false' otherwise.
103 	 */
104 	public void hasArgs(String name, Object type, char separator, boolean isOptional) {
105 		hasArgs(Option.UNLIMITED_VALUES, name, type, separator, isOptional);
106 	}
107 	
108 	/***
109 	 * Defines an argument's "properties" for an option.
110 	 * 
111 	 * @param numArgs Max number of arguments allowed.
112 	 * @param name Sets the display name of the argument value.
113 	 * @param type Sets the data type allowed for this argument.
114 	 * @param separator Sets the separator value allowed in between the
115 	 * argument values being passed in.
116 	 * @param isOptional Set to 'true' if an argument is optional, 'false'
117 	 * otherwise.
118 	 */
119 	public void hasArgs(int numArgs, String name, Object type, char separator, boolean isOptional) {
120 		setArgs(numArgs);
121 		setArgName(name);
122 		setType(type);
123 		setValueSeparator(separator);
124 		setOptionalArg(isOptional);
125 	}
126 
127 }