2014-04-12 22:00:28 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
class CommandBuilder
|
2015-07-09 23:46:27 +00:00
|
|
|
def initialize(config, client_type, is_windows = false, is_ui_colored = false)
|
2014-04-26 02:51:18 +00:00
|
|
|
@client_type = client_type
|
|
|
|
@config = config
|
|
|
|
@is_windows = is_windows
|
|
|
|
@is_ui_colored = is_ui_colored
|
2014-04-12 22:00:28 +00:00
|
|
|
|
|
|
|
if client_type != :solo && client_type != :client
|
|
|
|
raise 'Invalid client_type, expected solo or client'
|
|
|
|
end
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
|
|
|
|
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
|
2015-07-09 23:46:27 +00:00
|
|
|
binary_path = File.join(@config.binary_path, binary_path)
|
|
|
|
if windows?
|
|
|
|
binary_path = windows_friendly_path(binary_path)
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
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
|
2015-07-09 23:46:27 +00:00
|
|
|
chef_arguments << " --no-color" unless color?
|
2014-04-26 02:51:18 +00:00
|
|
|
chef_arguments.strip
|
|
|
|
end
|
|
|
|
|
|
|
|
def provisioning_path(file)
|
2015-07-09 23:46:27 +00:00
|
|
|
if windows?
|
|
|
|
path = @config.provisioning_path || "C:/vagrant-chef"
|
|
|
|
return windows_friendly_path(File.join(path, file))
|
|
|
|
else
|
|
|
|
path = @config.provisioning_path || "/tmp/vagrant-chef"
|
|
|
|
return File.join(path, file)
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-09 23:46:27 +00:00
|
|
|
def windows_friendly_path(path)
|
|
|
|
path = path.gsub("/", "\\")
|
2014-04-26 02:51:18 +00:00
|
|
|
path = "c:#{path}" if path.start_with?("\\")
|
2015-07-09 23:46:27 +00:00
|
|
|
return path
|
|
|
|
end
|
|
|
|
|
|
|
|
def windows?
|
|
|
|
!!@is_windows
|
|
|
|
end
|
|
|
|
|
|
|
|
def color?
|
|
|
|
!!@is_ui_colored
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
2014-04-12 22:00:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|