Class: Fuelcell::Parser::OptHandler

Inherits:
BaseHandler show all
Defined in:
lib/fuelcell/parser/opt_handler.rb

Overview

Process options that are flags or use another arg as their value. This handles both short and long options. Flags are assigned a value of true while all other values are casted during value assignment

Instance Method Summary collapse

Methods inherited from BaseHandler

#arg?, #assign_opt_value, #cast, #cast_array, #cast_bool, #cast_hash, #cast_numeric, #find_opt, #found_opt_flag, #take_first_arg

Instance Method Details

#call(cmd, args, opts) ⇒ Boolean

Parameters:

  • cmd (Fuelcell::Command)
  • args (Array)

    raw args from ARGV

  • opts (Hash)

    stores the found opts

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fuelcell/parser/opt_handler.rb', line 11

def call(cmd, args, opts)
  arg = take_first_arg(args) do |text|
    !(text =~ /^(--\w+(?:-\w+)*|-[a-zA-Z])$/).nil?
  end
  return false unless arg

  opt = find_opt(cmd, arg)
  return true if handled_flag?(opts, opt)

  # We know we are not a flag, so we are expecting a value.
  # We also know there are no other values available so for now
  # this is considered a failure condition
  fail_value_required(opt) if args.empty?

  handle_value(opts, opt, arg, args)
  true
end