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