vagrant init: Support VAGRANT_DEFAULT_TEMPLATE

This commit is contained in:
Sebastian Reuße 2018-09-04 10:39:49 +02:00
parent 07092bc36f
commit 3efdc8960c
3 changed files with 22 additions and 1 deletions

View File

@ -14,7 +14,7 @@ module VagrantPlugins
force: false, force: false,
minimal: false, minimal: false,
output: "Vagrantfile", output: "Vagrantfile",
template: nil template: ENV["VAGRANT_DEFAULT_TEMPLATE"]
} }
opts = OptionParser.new do |o| opts = OptionParser.new do |o|

View File

@ -55,6 +55,22 @@ describe VagrantPlugins::CommandInit::Command do
expect(contents).to match(/config.vm.hostname = "vagrant.dev"/) expect(contents).to match(/config.vm.hostname = "vagrant.dev"/)
end end
it "creates a custom Vagrant file using a template provided from the environment" do
with_temp_env("VAGRANT_DEFAULT_TEMPLATE" => "test/unit/templates/commands/init/Vagrantfile") do
described_class.new([], env).execute
end
contents = File.read(vagrantfile_path)
expect(contents).to match(/config.vm.hostname = "vagrant.dev"/)
end
it "ignores the environmentally-set default template when a template is explicitly set" do
with_temp_env("VAGRANT_DEFAULT_TEMPLATE" => "/this_file_does_not_exist") do
described_class.new(["--template", "test/unit/templates/commands/init/Vagrantfile"], env).execute
end
contents = File.read(vagrantfile_path)
expect(contents).to match(/config.vm.hostname = "vagrant.dev"/)
end
it "ignores the -m option when using a provided template" do it "ignores the -m option when using a provided template" do
described_class.new(["-m", "--template", ::Vagrant.source_root.join("test/unit/templates/commands/init/Vagrantfile").to_s], env).execute described_class.new(["-m", "--template", ::Vagrant.source_root.join("test/unit/templates/commands/init/Vagrantfile").to_s], env).execute
contents = File.read(vagrantfile_path) contents = File.read(vagrantfile_path)

View File

@ -37,6 +37,11 @@ Vagrant to use this provider for any _new_ Vagrant environments. Existing
Vagrant environments will continue to use the provider they came `up` with. Vagrant environments will continue to use the provider they came `up` with.
Once you `vagrant destroy` existing environments, this will take effect. Once you `vagrant destroy` existing environments, this will take effect.
## `VAGRANT_DEFAULT_TEMPLATE`
This configures the template used by `vagrant init` when the `--template` option
is not provided.
## `VAGRANT_PREFERRED_PROVIDERS` ## `VAGRANT_PREFERRED_PROVIDERS`
This configures providers that Vagrant should prefer. This configures providers that Vagrant should prefer.