Sha256: 515b99edce1cf7f9c789825c3427a86ae4ce2f2b808fa2ba3b2ef54c381a0335

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

module VagrantPlugins
  module Chef
    class CommandBuilder
      def initialize(config, client_type, is_windows=false, is_ui_colored=false)
        @client_type   = client_type
        @config        = config
        @is_windows    = is_windows
        @is_ui_colored = is_ui_colored

        if client_type != :solo && client_type != :client
          raise 'Invalid client_type, expected solo or client'
        end
      end

      def build_command
        "#{command_env}#{chef_binary_path} #{chef_arguments}"
      end

      protected

      def command_env
        @config.binary_env ? "#{@config.binary_env} " : ""
      end

      def chef_binary_path
        binary_path = "chef-#{@client_type}"
        if @config.binary_path
          binary_path = guest_friendly_path(File.join(@config.binary_path, binary_path))
        end
        binary_path
      end

      def chef_arguments
        chef_arguments = "-c #{provisioning_path("#{@client_type}.rb")}"
        chef_arguments << " -j #{provisioning_path("dna.json")}"
        chef_arguments << " #{@config.arguments}" if @config.arguments
        chef_arguments << " --no-color" unless @is_ui_colored
        chef_arguments.strip
      end

      def provisioning_path(file)
        guest_friendly_path(File.join(@config.provisioning_path, file))
      end

      def guest_friendly_path(path)
        return path unless @is_windows
        path.gsub!("/", "\\")
        path = "c:#{path}" if path.start_with?("\\")
        path
      end
    end
  end
end

Version data entries

5 entries across 2 versions & 2 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/plugins/provisioners/chef/command_builder.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/plugins/provisioners/chef/command_builder.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/plugins/provisioners/chef/command_builder.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/plugins/provisioners/chef/command_builder.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/plugins/provisioners/chef/command_builder.rb