`vagrant init` command. Used for initializing directories with vagrant.
This commit is contained in:
parent
fef985009f
commit
7ff428d5c2
|
@ -5,3 +5,4 @@ Vagrantfile
|
||||||
*.lock
|
*.lock
|
||||||
cookbooks/*
|
cookbooks/*
|
||||||
_site/*
|
_site/*
|
||||||
|
!templates/*
|
|
@ -7,9 +7,21 @@ module Vagrant
|
||||||
extend Vagrant::Util
|
extend Vagrant::Util
|
||||||
|
|
||||||
class <<self
|
class <<self
|
||||||
# TODO: Coming soon to a theatre near you.
|
# Initializes a directory for use with vagrant. This command copies an
|
||||||
|
# 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
|
||||||
|
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
|
||||||
|
if File.exist?(rootfile_path)
|
||||||
|
error_and_exit(<<-error)
|
||||||
|
It looks like this directory is already setup for vagrant! (A #{Env::ROOTFILE_NAME}
|
||||||
|
already exists.)
|
||||||
|
error
|
||||||
|
end
|
||||||
|
|
||||||
|
# Copy over the rootfile template into this directory
|
||||||
|
File.copy(File.join(PROJECT_ROOT, "templates", Env::ROOTFILE_NAME), rootfile_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Bring up a vagrant instance. This handles everything from importing
|
# Bring up a vagrant instance. This handles everything from importing
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
Vagrant::Config.run do |config|
|
||||||
|
# All Vagrant configuration is done here. For a detailed explanation
|
||||||
|
# and listing of configuration options, please check the documentation
|
||||||
|
# online.
|
||||||
|
end
|
|
@ -8,6 +8,26 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "init" do
|
||||||
|
setup do
|
||||||
|
File.stubs(:copy)
|
||||||
|
@rootfile_path = File.join(Dir.pwd, Vagrant::Env::ROOTFILE_NAME)
|
||||||
|
@template_path = File.join(PROJECT_ROOT, "templates", Vagrant::Env::ROOTFILE_NAME)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "error and exit if a rootfile already exists" do
|
||||||
|
File.expects(:exist?).with(@rootfile_path).returns(true)
|
||||||
|
Vagrant::Commands.expects(:error_and_exit).once
|
||||||
|
Vagrant::Commands.init
|
||||||
|
end
|
||||||
|
|
||||||
|
should "copy the templated rootfile to the current path" do
|
||||||
|
File.expects(:exist?).with(@rootfile_path).returns(false)
|
||||||
|
File.expects(:copy).with(@template_path, @rootfile_path).once
|
||||||
|
Vagrant::Commands.init
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "up" do
|
context "up" do
|
||||||
setup do
|
setup do
|
||||||
Vagrant::Env.stubs(:persisted_vm).returns(nil)
|
Vagrant::Env.stubs(:persisted_vm).returns(nil)
|
||||||
|
|
Loading…
Reference in New Issue