diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc94af83..f345f91dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index 1b644b4cd..c8267834f 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -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") - raise Vagrant::Errors::VagrantfileExistsError if save_path.exist? + 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]) - # Write out the contents - save_path.open("w+") do |f| - f.write(contents) - end + 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