1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.cli2; 18 19 import java.util.List; 20 import java.util.Set; 21 22 /** 23 * Instances of CommandLine represent a command line that has been processed 24 * according to the definition supplied to the parser. 25 */ 26 public interface CommandLine { 27 28 /** 29 * Detects the presence of an option with the specified trigger in this 30 * CommandLine. 31 * 32 * @param trigger the trigger to search for 33 * @return true iff an option with this trigger is present 34 */ 35 boolean hasOption(final String trigger); 36 37 /** 38 * Detects the presence of an option in this CommandLine. 39 * 40 * @param option the Option to search for 41 * @return true iff the option is present 42 */ 43 boolean hasOption(final Option option); 44 45 /** 46 * Finds the Option with the specified trigger 47 * 48 * @param trigger the name of the option to retrieve 49 * @return the Option matching the trigger or null if none exists 50 */ 51 Option getOption(final String trigger); 52 53 /** 54 * Retrieves the Argument values associated with the specified Option 55 * 56 * @param trigger a trigger used to lookup the Option 57 * @return a list of values or an empty List if none are found 58 */ 59 List getValues(final String trigger); 60 61 /** 62 * Retrieves the Argument values associated with the specified Option 63 * 64 * @param trigger a trigger used to lookup the Option 65 * @param defaultValues the result to return if no values are found 66 * @return a list of values or defaultValues if none are found 67 */ 68 List getValues(final String trigger, final List defaultValues); 69 70 /** 71 * Retrieves the Argument values associated with the specified Option 72 * 73 * @param option the Option associated with the values 74 * @return a list of values or an empty List if none are found 75 */ 76 List getValues(final Option option); 77 78 /** 79 * Retrieves the Argument values associated with the specified Option 80 * 81 * @param option the Option associated with the values 82 * @param defaultValues the result to return if no values are found 83 * @return a list of values or defaultValues if none are found 84 */ 85 List getValues(final Option option, final List defaultValues); 86 87 /** 88 * Retrieves the single Argument value associated with the specified Option 89 * 90 * @param trigger a trigger used to lookup the Option 91 * @return the matching value or null if none exists 92 * @throws IllegalStateException if more than one values are found 93 */ 94 Object getValue(final String trigger) throws IllegalStateException; 95 96 /** 97 * Retrieves the single Argument value associated with the specified Option 98 * 99 * @param trigger a trigger used to lookup the Option 100 * @param defaultValue the result to use if no values are found 101 * @return the matching value or defaultValue if none exists 102 * @throws IllegalStateException if more than one values are found 103 */ 104 Object getValue(final String trigger, final Object defaultValue) throws IllegalStateException; 105 106 /** 107 * Retrieves the single Argument value associated with the specified Option 108 * 109 * @param option the Option associated with the value 110 * @return the matching value or null if none exists 111 * @throws IllegalStateException if more than one values are found 112 */ 113 Object getValue(final Option option) throws IllegalStateException; 114 115 /** 116 * Retrieves the single Argument value associated with the specified Option 117 * 118 * @param option the Option associated with the value 119 * @param defaultValue the result to use if no values are found 120 * @return the matching value or defaultValue if none exists 121 * @throws IllegalStateException if more than one values are found 122 */ 123 Object getValue(final Option option, final Object defaultValue) throws IllegalStateException; 124 125 /** 126 * Retrieves the Boolean value associated with the specified Switch 127 * 128 * @param trigger a trigger used to lookup the Option 129 * @return the Boolean associated with trigger or null if none exists 130 */ 131 Boolean getSwitch(final String trigger); 132 133 /** 134 * Retrieves the Boolean value associated with the specified Switch 135 * 136 * @param trigger a trigger used to lookup the Option 137 * @param defaultValue the Boolean to use if none match 138 * @return the Boolean associated with trigger or defaultValue if none exists 139 */ 140 Boolean getSwitch(final String trigger, final Boolean defaultValue); 141 142 /** 143 * Retrieves the Boolean value associated with the specified Switch 144 * 145 * @param option the Option associated with the value 146 * @return the Boolean associated with option or null if none exists 147 */ 148 Boolean getSwitch(final Option option); 149 150 /** 151 * Retrieves the Boolean value associated with the specified Switch 152 * 153 * @param option the Option associated with the value 154 * @param defaultValue the Boolean to use if none match 155 * @return the Boolean associated with option or defaultValue if none exists 156 */ 157 Boolean getSwitch(final Option option, final Boolean defaultValue); 158 159 160 /** 161 * Retrieves the value associated with the specified property for the default property set 162 * 163 * @param property the property name to lookup 164 * @return the value of the property or null 165 */ 166 String getProperty(final String property); 167 168 /** 169 * Retrieves the value associated with the specified property 170 * 171 * @param option the option i.e., -D 172 * @param property the property name to lookup 173 * @return the value of the property or null 174 */ 175 String getProperty(final Option option, final String property); 176 177 /** 178 * Retrieves the value associated with the specified property 179 * 180 * @param option the option i.e., -D 181 * @param property the property name to lookup 182 * @param defaultValue the value to use if no other is found 183 * @return the value of the property or defaultValue 184 */ 185 String getProperty(final Option option, final String property, final String defaultValue); 186 187 /** 188 * Retrieves the set of all property names associated with this option 189 * 190 * @param option the option i.e., -D 191 * @return a none null set of property names 192 */ 193 Set getProperties(final Option option); 194 195 /** 196 * Retrieves the set of all property names associated with the default property option 197 * 198 * @return a none null set of property names 199 */ 200 Set getProperties(); 201 202 /** 203 * Retrieves the number of times the specified Option appeared in this 204 * CommandLine 205 * 206 * @param trigger a trigger used to lookup the Option 207 * @return the number of occurrences of the option 208 */ 209 int getOptionCount(final String trigger); 210 211 /** 212 * Retrieves the number of times the specified Option appeared in this 213 * CommandLine 214 * 215 * @param option the Option associated to check 216 * @return the number of occurrences of the option 217 */ 218 int getOptionCount(final Option option); 219 220 /** 221 * Retrieves a list of all Options found in this CommandLine 222 * 223 * @return a none null list of Options 224 */ 225 List getOptions(); 226 227 /** 228 * Retrieves a list of all Option triggers found in this CommandLine 229 * 230 * @return a none null list of Option triggers 231 */ 232 Set getOptionTriggers(); 233 }