Sha256: 24ce27d3605d94d397842d4f43417009fc0b4a2893b78b4d84a0d6c9554afb1f

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

module Vagrant
  module Util
    class MapCommandOptions
      # 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.
      # {a: "opt-a", b: true} -> ["--a", "opt-a", "--b"]
      #
      # @param [Hash]   map of commands
      # @param [String] string prepended to cmd line flags (keys)
      #
      # @return[Array<String>] commands in list form
      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
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/util/map_command_options.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/map_command_options.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/util/map_command_options.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/util/map_command_options.rb