Add --template option to init command, with graceful fallback to default Vagrantfile template behavior
This commit is contained in:
parent
bcf3a4b3d1
commit
14d596f08e
|
@ -14,6 +14,7 @@ module VagrantPlugins
|
||||||
force: false,
|
force: false,
|
||||||
minimal: false,
|
minimal: false,
|
||||||
output: "Vagrantfile",
|
output: "Vagrantfile",
|
||||||
|
template: nil
|
||||||
}
|
}
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
|
@ -30,7 +31,7 @@ module VagrantPlugins
|
||||||
options[:force] = f
|
options[:force] = f
|
||||||
end
|
end
|
||||||
|
|
||||||
o.on("-m", "--minimal", "Create minimal Vagrantfile (no help comments)") do |m|
|
o.on("-m", "--minimal", "Use minimal Vagrantfile template (no help comments). Ignored with --template") do |m|
|
||||||
options[:minimal] = m
|
options[:minimal] = m
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,6 +39,10 @@ module VagrantPlugins
|
||||||
"Output path for the box. '-' for stdout") do |output|
|
"Output path for the box. '-' for stdout") do |output|
|
||||||
options[:output] = output
|
options[:output] = output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.on("--template FILE", String, "Path to Vagrantfile template") do |template|
|
||||||
|
options[:template] = template
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
|
@ -51,16 +56,26 @@ module VagrantPlugins
|
||||||
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
template = "templates/commands/init/Vagrantfile"
|
# Determine the template and template root to use
|
||||||
if options[:minimal]
|
template_root = ""
|
||||||
template = "templates/commands/init/Vagrantfile.min"
|
if options[:template].nil?
|
||||||
|
options[:template] = "Vagrantfile"
|
||||||
|
|
||||||
|
if options[:minimal]
|
||||||
|
options[:template] = "Vagrantfile.min"
|
||||||
|
end
|
||||||
|
|
||||||
|
template_root = ::Vagrant.source_root.join("templates/commands/init")
|
||||||
end
|
end
|
||||||
|
|
||||||
template_path = ::Vagrant.source_root.join(template)
|
# Strip the .erb extension off the template if the user passes it in
|
||||||
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
options[:template] = options[:template].chomp(".erb")
|
||||||
|
|
||||||
|
contents = Vagrant::Util::TemplateRenderer.render(options[:template],
|
||||||
box_name: argv[0] || "base",
|
box_name: argv[0] || "base",
|
||||||
box_url: argv[1],
|
box_url: argv[1],
|
||||||
box_version: options[:box_version],
|
box_version: options[:box_version],
|
||||||
|
template_root: template_root
|
||||||
)
|
)
|
||||||
|
|
||||||
if save_path
|
if save_path
|
||||||
|
|
Loading…
Reference in New Issue