commands/init: add --output flag [GH-1364]
This commit is contained in:
parent
7c7524a840
commit
7ba9d2d0a0
|
@ -18,6 +18,8 @@ IMPROVEMENTS:
|
||||||
|
|
||||||
- core: Support resumable downloads [GH-57]
|
- core: Support resumable downloads [GH-57]
|
||||||
- core: owner/group of shared folders can be specified by integers. [GH-2390]
|
- core: owner/group of shared folders can be specified by integers. [GH-2390]
|
||||||
|
- commands/init: Add `--output` option for specifing output path, or
|
||||||
|
"-" for stdin. [GH-1364]
|
||||||
- commands/provision: Add `--no-parallel` option to disable provider
|
- commands/provision: Add `--no-parallel` option to disable provider
|
||||||
parallelization if the provider supports it. [GH-2404]
|
parallelization if the provider supports it. [GH-2404]
|
||||||
- commands/ssh: SSH compression is enabled by default. [GH-2456]
|
- commands/ssh: SSH compression is enabled by default. [GH-2456]
|
||||||
|
|
|
@ -10,29 +10,42 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
options = { output: "Vagrantfile" }
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: vagrant init [box-name] [box-url]"
|
o.banner = "Usage: vagrant init [box-name] [box-url]"
|
||||||
|
|
||||||
|
o.on("--output FILENAME", String,
|
||||||
|
"Output path for the box. '-' for stdout.") do |output|
|
||||||
|
options[:output] = output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
save_path = @env.cwd.join("Vagrantfile")
|
save_path = nil
|
||||||
|
if options[:output] != "-"
|
||||||
|
save_path = Pathname.new(options[:output]).expand_path(@env.cwd)
|
||||||
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
raise Vagrant::Errors::VagrantfileExistsError if save_path.exist?
|
||||||
|
end
|
||||||
|
|
||||||
template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile")
|
template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile")
|
||||||
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
contents = Vagrant::Util::TemplateRenderer.render(template_path,
|
||||||
:box_name => argv[0] || "base",
|
:box_name => argv[0] || "base",
|
||||||
:box_url => argv[1])
|
:box_url => argv[1])
|
||||||
|
|
||||||
|
if save_path
|
||||||
# Write out the contents
|
# Write out the contents
|
||||||
save_path.open("w+") do |f|
|
save_path.open("w+") do |f|
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
@env.ui.info(I18n.t("vagrant.commands.init.success"),
|
@env.ui.info(I18n.t("vagrant.commands.init.success"), prefix: false)
|
||||||
:prefix => false)
|
else
|
||||||
|
@env.ui.info(contents, prefix: false)
|
||||||
|
end
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
0
|
0
|
||||||
|
|
Loading…
Reference in New Issue