`vagrant init` now takes an optional parameter to specify the default box [close GH-6]
This commit is contained in:
parent
0614882800
commit
4229b65a81
|
@ -22,6 +22,6 @@ Creates the initial files required for using vagrant.
|
|||
EOS
|
||||
|
||||
run do |command|
|
||||
Vagrant::Commands.init
|
||||
Vagrant::Commands.init(command.argv[0])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ PROJECT_ROOT = File.join(libdir, '..') unless defined?(PROJECT_ROOT)
|
|||
|
||||
# The libs which must be loaded prior to the rest
|
||||
%w{tempfile open-uri json pathname logger uri net/http virtualbox net/ssh archive/tar/minitar
|
||||
net/scp fileutils ostruct}.each do |lib|
|
||||
net/scp fileutils ostruct erb}.each do |lib|
|
||||
require lib
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Vagrant
|
|||
# initial `Vagrantfile` into the current working directory so you can
|
||||
# begin using vagrant. The configuration file contains some documentation
|
||||
# to get you started.
|
||||
def init
|
||||
def init(default_box=nil)
|
||||
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
|
||||
if File.exist?(rootfile_path)
|
||||
error_and_exit(<<-error)
|
||||
|
@ -21,7 +21,10 @@ error
|
|||
end
|
||||
|
||||
# Copy over the rootfile template into this directory
|
||||
FileUtils.cp(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path)
|
||||
default_box ||= "base"
|
||||
File.open(rootfile_path, 'w+') do |f|
|
||||
f.write(TemplateRenderer.render!(Env::ROOTFILE_NAME, :default_box => default_box))
|
||||
end
|
||||
end
|
||||
|
||||
# Outputs the status of the current environment. This command outputs
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
Vagrant::Config.run do |config|
|
||||
# All Vagrant configuration is done here. For a detailed explanation
|
||||
# and listing of configuration options, please check the documentation
|
||||
# and listing of configuration options, please view the documentation
|
||||
# online.
|
||||
|
||||
# Every Vagrant virtual environment requires a box to build off of.
|
||||
config.vm.box = "base"
|
||||
config.vm.box = "<%= default_box %>"
|
||||
end
|
|
@ -12,9 +12,12 @@ class CommandsTest < Test::Unit::TestCase
|
|||
|
||||
context "init" do
|
||||
setup do
|
||||
FileUtils.stubs(:cp)
|
||||
@file = mock("file")
|
||||
@file.stubs(:write)
|
||||
File.stubs(:open).yields(@file)
|
||||
@rootfile_path = File.join(Dir.pwd, Vagrant::Env::ROOTFILE_NAME)
|
||||
@template_path = File.join(PROJECT_ROOT, "templates", Vagrant::Env::ROOTFILE_NAME)
|
||||
|
||||
Vagrant::TemplateRenderer.stubs(:render!)
|
||||
end
|
||||
|
||||
should "error and exit if a rootfile already exists" do
|
||||
|
@ -23,9 +26,23 @@ class CommandsTest < Test::Unit::TestCase
|
|||
Vagrant::Commands.init
|
||||
end
|
||||
|
||||
should "copy the templated rootfile to the current path" do
|
||||
File.expects(:exist?).with(@rootfile_path).returns(false)
|
||||
FileUtils.expects(:cp).with(@template_path, @rootfile_path).once
|
||||
should "write to the rootfile path using the template renderer" do
|
||||
result = "foo"
|
||||
Vagrant::TemplateRenderer.expects(:render!).returns(result).once
|
||||
@file.expects(:write).with(result).once
|
||||
File.expects(:open).with(@rootfile_path, 'w+').yields(@file)
|
||||
|
||||
Vagrant::Commands.init
|
||||
end
|
||||
|
||||
should "use the given base box if given" do
|
||||
box = "zooo"
|
||||
Vagrant::TemplateRenderer.expects(:render!).with(Vagrant::Env::ROOTFILE_NAME, :default_box => box)
|
||||
Vagrant::Commands.init(box)
|
||||
end
|
||||
|
||||
should "use the default `base` if no box is given" do
|
||||
Vagrant::TemplateRenderer.expects(:render!).with(Vagrant::Env::ROOTFILE_NAME, :default_box => "base")
|
||||
Vagrant::Commands.init
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue