Class: LibCLImate::Climate::ParseResults
- Inherits:
-
Object
- Object
- LibCLImate::Climate::ParseResults
- Defined in:
- lib/libclimate/climate.rb
Overview
Represents the results obtained from Climate#parse()
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
([String]) The original arguments passed into the Climate#parse() method.
-
#argv_original_copy ⇒ Object
readonly
(Array) unchanged copy of the original array of arguments passed to parse.
-
#climate ⇒ Object
readonly
(Climate) The
Climate
instance from which this instance was obtained. -
#double_slash_index ⇒ Object
readonly
Returns the value of attribute double_slash_index.
-
#flags ⇒ Object
readonly
(String) A (frozen) array of flags.
-
#options ⇒ Object
readonly
(String) A (frozen) array of options.
-
#program_name ⇒ Object
readonly
(String) The program name.
-
#specifications ⇒ Object
readonly
(Array) a frozen array of specifications.
-
#values ⇒ Object
readonly
(String) A (frozen) array of values.
Instance Method Summary collapse
- #flag_is_specified(id) ⇒ Object
-
#initialize(climate, arguments, options) ⇒ ParseResults
constructor
A new instance of ParseResults.
- #lookup_flag(id) ⇒ Object
- #lookup_option(id) ⇒ Object
-
#verify(**options) ⇒ Object
Verifies the initiating command-line against the specifications, raising an exception if any missing, unused, or unrecognised flags, options, or values are found.
Constructor Details
#initialize(climate, arguments, options) ⇒ ParseResults
Returns a new instance of ParseResults.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/libclimate/climate.rb', line 174 def initialize(climate, arguments, ) @climate = climate @arguments = arguments @argv = arguments.argv @argv_original_copy = arguments.argv_original_copy @specifications = arguments.specifications @program_name = climate.program_name @flags = arguments.flags @options = arguments. @values = arguments.values @double_slash_index = arguments.double_slash_index end |
Instance Attribute Details
#argv ⇒ Object (readonly)
([String]) The original arguments passed into the Climate#parse() method
194 195 196 |
# File 'lib/libclimate/climate.rb', line 194 def argv @argv end |
#argv_original_copy ⇒ Object (readonly)
(Array) unchanged copy of the original array of arguments passed to parse
197 198 199 |
# File 'lib/libclimate/climate.rb', line 197 def argv_original_copy @argv_original_copy end |
#climate ⇒ Object (readonly)
(Climate) The Climate
instance from which this instance was obtained
191 192 193 |
# File 'lib/libclimate/climate.rb', line 191 def climate @climate end |
#double_slash_index ⇒ Object (readonly)
Returns the value of attribute double_slash_index.
214 215 216 |
# File 'lib/libclimate/climate.rb', line 214 def double_slash_index @double_slash_index end |
#flags ⇒ Object (readonly)
(String) A (frozen) array of flags
206 207 208 |
# File 'lib/libclimate/climate.rb', line 206 def flags @flags end |
#options ⇒ Object (readonly)
(String) A (frozen) array of options
209 210 211 |
# File 'lib/libclimate/climate.rb', line 209 def @options end |
#program_name ⇒ Object (readonly)
(String) The program name
203 204 205 |
# File 'lib/libclimate/climate.rb', line 203 def program_name @program_name end |
#specifications ⇒ Object (readonly)
(Array) a frozen array of specifications
200 201 202 |
# File 'lib/libclimate/climate.rb', line 200 def specifications @specifications end |
#values ⇒ Object (readonly)
(String) A (frozen) array of values
212 213 214 |
# File 'lib/libclimate/climate.rb', line 212 def values @values end |
Instance Method Details
#flag_is_specified(id) ⇒ Object
350 351 352 353 |
# File 'lib/libclimate/climate.rb', line 350 def flag_is_specified(id) !@arguments.find_flag(id).nil? end |
#lookup_flag(id) ⇒ Object
355 356 357 358 |
# File 'lib/libclimate/climate.rb', line 355 def lookup_flag(id) @arguments.find_flag(id) end |
#lookup_option(id) ⇒ Object
360 361 362 363 |
# File 'lib/libclimate/climate.rb', line 360 def lookup_option(id) @arguments.find_option(id) end |
#verify(**options) ⇒ Object
Verifies the initiating command-line against the specifications, raising an exception if any missing, unused, or unrecognised flags, options, or values are found
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/libclimate/climate.rb', line 219 def verify(**) if v = [:raise] hm = {} hm[:raise_on_required] = v unless .has_key?(:raise_on_required) hm[:raise_on_unrecognised] = v unless .has_key?(:raise_on_unrecognised) hm[:raise_on_unused] = v unless .has_key?(:raise_on_unused) = .merge hm end raise_on_required = [:raise_on_required] raise_on_unrecognised = [:raise_on_unrecognised] raise_on_unused = [:raise_on_unused] # Verification: # # 1. Check arguments recognised # 1.a Flags # 1.b Options # 2. police any required options # 3. Check values # 1.a Flags self.flags.each do |flag| spec = specifications.detect do |sp| sp.kind_of?(::CLASP::FlagSpecification) && flag.name == sp.name end if spec if spec.respond_to?(:action) && !spec.action.nil? spec.action.call(flag, spec) end else = ("unrecognised flag '#{f}'") if false elsif climate.ignore_unknown ; elsif raise_on_unrecognised if raise_on_unrecognised.is_a?(Class) raise raise_on_unrecognised, else raise RuntimeError, end elsif climate.exit_on_unknown climate.abort else if program_name && !program_name.empty? = "#{program_name}: #{}" end climate.stderr.puts end end end # 1.b Options self..each do |option| spec = specifications.detect do |sp| sp.kind_of?(::CLASP::OptionSpecification) && option.name == sp.name end if spec if spec.respond_to?(:action) && !spec.action.nil? spec.action.call(option, spec) end else = ("unrecognised option '#{f}'") if false elsif climate.ignore_unknown ; elsif raise_on_unrecognised if raise_on_unrecognised.is_a?(Class) raise raise_on_unrecognised, else raise RuntimeError, end elsif climate.exit_on_unknown climate.abort else if program_name && !program_name.empty? = "#{program_name}: #{}" end climate.stderr.puts end end end # 2. police any required options climate.(specifications, self., [], raise_on_required) # 3. Check values climate.check_value_constraints_(values) end |