Class: Vagrant::Util::MapCommandOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/util/map_command_options.rb

Class Method Summary collapse

Class Method Details

.map_to_command_options(map, cmd_flag = "--") ⇒ Object

Given a hash map of user specified argments, will generate a list. Set the key to the command flag, and the value to it's value. If the value is boolean (true), only the flag is added. eg. "opt-a", b: true -> ["--a", "opt-a", "--b"]

@return[Array] commands in list form

Parameters:

  • map (Hash)

    of commands

  • string (String)

    prepended to cmd line flags (keys)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant/util/map_command_options.rb', line 17

def self.map_to_command_options(map, cmd_flag="--")
  opt_list = []
  if map == nil
    return opt_list
  end
  map.each do |k, v|
    # If the value is true (bool) add the key as the cmd flag
    if v.is_a?(TrueClass)
      opt_list.push("#{cmd_flag}#{k}")
    # If the value is a string, add the key as the flag, and value as the flags argument
    elsif v.is_a?(String)
      opt_list.push("#{cmd_flag}#{k}")
      opt_list.push(v)
    end
  end
  return opt_list
end