commands/init: add --output flag [GH-1364]

This commit is contained in:
Mitchell Hashimoto 2013-11-24 11:53:08 -08:00
parent 7c7524a840
commit 7ba9d2d0a0
2 changed files with 23 additions and 8 deletions

View File

@ -18,6 +18,8 @@ IMPROVEMENTS:
- core: Support resumable downloads [GH-57]
- 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
parallelization if the provider supports it. [GH-2404]
- commands/ssh: SSH compression is enabled by default. [GH-2456]

View File

@ -10,29 +10,42 @@ module VagrantPlugins
end
def execute
options = { output: "Vagrantfile" }
opts = OptionParser.new do |o|
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
# Parse the options
argv = parse_options(opts)
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?
end
template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile")
contents = Vagrant::Util::TemplateRenderer.render(template_path,
:box_name => argv[0] || "base",
:box_url => argv[1])
if save_path
# Write out the contents
save_path.open("w+") do |f|
f.write(contents)
end
@env.ui.info(I18n.t("vagrant.commands.init.success"),
:prefix => false)
@env.ui.info(I18n.t("vagrant.commands.init.success"), prefix: false)
else
@env.ui.info(contents, prefix: false)
end
# Success, exit status 0
0