Method: Chid::Command.map_options_with_values

Defined in:
lib/chid/command.rb

.map_options_with_values(argv) ⇒ Hash<String, Array>

Returns a mapped options with your values from @argv

Examples:

Map an argv

argv = ['init', '-option_1', 'value_for_option_1']

map_options_with_values(argv) #=> {'-option1' => ['value_for_option_1']}

Parameters:

  • argv (Array<String>)

    The arguments passed from input.

Returns:

  • (Hash<String, Array>)

    Mapped options with your values The keys of hash are the options and the values of hash are all values for the option.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chid/command.rb', line 57

def map_options_with_values(argv)
  return argv.reduce({}) do |options, arg|
    new_options = options

    if arg_is_an_option?(arg)
      new_options[arg] = []
      next(new_options)
    end

   options_with_values(new_options, arg)
  end
end