2014-04-12 22:00:28 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
class CommandBuilder
|
2015-07-10 03:23:42 +00:00
|
|
|
def self.command(type, config, options = {})
|
|
|
|
new(type, config, options).command
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :type
|
|
|
|
attr_reader :config
|
|
|
|
attr_reader :options
|
|
|
|
|
|
|
|
def initialize(type, config, options = {})
|
|
|
|
@type = type
|
|
|
|
@config = config
|
|
|
|
@options = options.dup
|
2014-04-12 22:00:28 +00:00
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
if type != :client && type != :solo
|
|
|
|
raise "Unknown type `#{type.inspect}'!"
|
2014-04-12 22:00:28 +00:00
|
|
|
end
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
def command
|
|
|
|
if config.binary_env
|
|
|
|
"#{config.binary_env} #{binary_path} #{args}"
|
|
|
|
else
|
|
|
|
"#{binary_path} #{args}"
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
def binary_path
|
|
|
|
binary_path = "chef-#{type}"
|
2014-04-26 02:51:18 +00:00
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
if config.binary_path
|
|
|
|
binary_path = File.join(config.binary_path, binary_path)
|
2015-07-09 23:46:27 +00:00
|
|
|
if windows?
|
|
|
|
binary_path = windows_friendly_path(binary_path)
|
|
|
|
end
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
2015-07-10 03:23:42 +00:00
|
|
|
|
2014-04-26 02:51:18 +00:00
|
|
|
binary_path
|
|
|
|
end
|
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
def args
|
|
|
|
args = ""
|
|
|
|
args << " --config #{provisioning_path("#{type}.rb")}"
|
|
|
|
args << " --json-attributes #{provisioning_path("dna.json")}"
|
|
|
|
args << " --local-mode" if options[:local_mode]
|
|
|
|
args << " --log_level #{config.log_level}" if config.log_level
|
|
|
|
args << " --no-color" if !options[:colored]
|
2015-11-19 19:45:09 +00:00
|
|
|
|
2015-11-19 22:56:18 +00:00
|
|
|
if config.install && (config.version == :latest || config.version >= "11.0")
|
2015-11-19 19:45:09 +00:00
|
|
|
args << " --force-formatter"
|
|
|
|
end
|
|
|
|
|
2015-07-10 03:23:42 +00:00
|
|
|
args << " #{config.arguments.strip}" if config.arguments
|
|
|
|
|
|
|
|
args.strip
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def provisioning_path(file)
|
2015-07-09 23:46:27 +00:00
|
|
|
if windows?
|
2015-07-10 03:23:42 +00:00
|
|
|
path = config.provisioning_path || "C:/vagrant-chef"
|
2015-07-09 23:46:27 +00:00
|
|
|
return windows_friendly_path(File.join(path, file))
|
|
|
|
else
|
2015-07-10 03:23:42 +00:00
|
|
|
path = config.provisioning_path || "/tmp/vagrant-chef"
|
2015-07-09 23:46:27 +00:00
|
|
|
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?
|
2015-07-10 03:23:42 +00:00
|
|
|
!!options[:windows]
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
2014-04-12 22:00:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|