`vagrant up`

This commit is contained in:
Mitchell Hashimoto 2010-08-24 23:03:37 -07:00
parent ccad6af8cf
commit 8340472fc5
4 changed files with 47 additions and 4 deletions

View File

@ -1,9 +1,15 @@
module Vagrant
module Command
module Helpers
def require_environment
raise NoEnvironmentError.new("No Vagrant environment detected. Run `vagrant init` to set one up.") if !env.root_path
end
# This returns an array of {VM} objects depending on the arguments
# given to the command.
def target_vms
require_environment
@target_vms ||= begin
if env.multivm?
return env.vms if !self.name

View File

@ -5,11 +5,8 @@ module Vagrant
argument :name, :type => :string, :optional => true
register "status"
def verify_environment
raise NoEnvironmentError.new("No Vagrant environment detected. Run `vagrant init` to set one up.") if !env.root_path
end
def route
require_environment
show_multivm if target_vms.length > 1
show_single(target_vms.first)
end

23
lib/vagrant/command/up.rb Normal file
View File

@ -0,0 +1,23 @@
module Vagrant
module Command
class UpCommand < Base
desc "Creates the Vagrant environment"
argument :name, :type => :string, :optional => true
class_option :provision, :type => :boolean, :default => true
register "up"
def execute
# TODO: Make the options[:provision] actually mean something
target_vms.each do |vm|
if vm.created?
vm.env.ui.info "VM already created. Booting if its not already running..."
vm.start
else
vm.up
end
end
end
end
end
end

View File

@ -12,9 +12,26 @@ class CommandHelpersTest < Test::Unit::TestCase
@command.new(args, {}, { :env => env })
end
context "requiring environment" do
setup do
@env = mock_environment
end
should "raise an exception if no environment" do
@env.stubs(:root_path).returns(nil)
assert_raises(Vagrant::NoEnvironmentError) { command([], @env).require_environment }
end
should "not raise an exception if there is an environment" do
@env.stubs(:root_path).returns(7)
assert_nothing_raised { command([], @env).require_environment }
end
end
context "vms from args" do
setup do
@env = mock_environment
@env.stubs(:root_path).returns(7)
end
should "only calculate the result once" do