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. -
#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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/libclimate/climate.rb', line 173 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 end |
Instance Attribute Details
#argv ⇒ Object (readonly)
([String]) The original arguments passed into the Climate#parse() method
192 193 194 |
# File 'lib/libclimate/climate.rb', line 192 def argv @argv end |
#argv_original_copy ⇒ Object (readonly)
(Array) unchanged copy of the original array of arguments passed to parse
195 196 197 |
# File 'lib/libclimate/climate.rb', line 195 def argv_original_copy @argv_original_copy end |
#climate ⇒ Object (readonly)
(Climate) The Climate
instance from which this instance was obtained
189 190 191 |
# File 'lib/libclimate/climate.rb', line 189 def climate @climate end |
#flags ⇒ Object (readonly)
(String) A (frozen) array of flags
204 205 206 |
# File 'lib/libclimate/climate.rb', line 204 def flags @flags end |
#options ⇒ Object (readonly)
(String) A (frozen) array of options
207 208 209 |
# File 'lib/libclimate/climate.rb', line 207 def @options end |
#program_name ⇒ Object (readonly)
(String) The program name
201 202 203 |
# File 'lib/libclimate/climate.rb', line 201 def program_name @program_name end |
#specifications ⇒ Object (readonly)
(Array) a frozen array of specifications
198 199 200 |
# File 'lib/libclimate/climate.rb', line 198 def specifications @specifications end |
#values ⇒ Object (readonly)
(String) A (frozen) array of values
210 211 212 |
# File 'lib/libclimate/climate.rb', line 210 def values @values end |
Instance Method Details
#flag_is_specified(id) ⇒ Object
346 347 348 349 |
# File 'lib/libclimate/climate.rb', line 346 def flag_is_specified(id) !@arguments.find_flag(id).nil? end |
#lookup_flag(id) ⇒ Object
351 352 353 354 |
# File 'lib/libclimate/climate.rb', line 351 def lookup_flag(id) @arguments.find_flag(id) end |
#lookup_option(id) ⇒ Object
356 357 358 359 |
# File 'lib/libclimate/climate.rb', line 356 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
215 216 217 218 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 |
# File 'lib/libclimate/climate.rb', line 215 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 |