diff --git a/CHANGELOG.md b/CHANGELOG.md index 640df906c..676bfd37a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ IMPROVEMENTS: 1 means everything was declined. 2 means some were declined. [GH-811] - commands/destroy: Doesn't require box to exist anymore. [GH-1629] - commands/init: force flag. [GH-3564] + - commands/init: flag for minimal Vagrantfile creation (no comments). [GH-3611] - commands/rsync-auto: Picks up and syncs provisioner folders if provisioners are backed by rsync. - commands/rsync-auto: Detects when new synced folders were added and warns diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index cf36ee3c6..b67b04db0 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -12,6 +12,7 @@ module VagrantPlugins def execute options = { force: false, + minimal: false, output: "Vagrantfile", } @@ -25,6 +26,10 @@ module VagrantPlugins options[:force] = f end + o.on("-m", "--minimal", "Create minimal Vagrantfile (no help comments)") do |m| + options[:minimal] = m + end + o.on("--output FILE", String, "Output path for the box. '-' for stdout") do |output| options[:output] = output @@ -42,7 +47,12 @@ module VagrantPlugins raise Vagrant::Errors::VagrantfileExistsError if save_path.exist? end - template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile") + template = "templates/commands/init/Vagrantfile" + if options[:minimal] + template = "templates/commands/init/Vagrantfile.min" + end + + template_path = ::Vagrant.source_root.join(template) contents = Vagrant::Util::TemplateRenderer.render(template_path, :box_name => argv[0] || "base", :box_url => argv[1]) diff --git a/templates/commands/init/Vagrantfile.min.erb b/templates/commands/init/Vagrantfile.min.erb new file mode 100644 index 000000000..a1f886d47 --- /dev/null +++ b/templates/commands/init/Vagrantfile.min.erb @@ -0,0 +1,12 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "<%= box_name %>" + <% if box_url -%> + config.vm.box_url = "<%= box_url %>" + <% end -%> +end