diff --git a/lib/vagrant/command/helpers.rb b/lib/vagrant/command/helpers.rb index d56640b6c..7a398d99f 100644 --- a/lib/vagrant/command/helpers.rb +++ b/lib/vagrant/command/helpers.rb @@ -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 diff --git a/lib/vagrant/command/status.rb b/lib/vagrant/command/status.rb index 7232ec7ed..1eaad207e 100644 --- a/lib/vagrant/command/status.rb +++ b/lib/vagrant/command/status.rb @@ -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 diff --git a/lib/vagrant/command/up.rb b/lib/vagrant/command/up.rb new file mode 100644 index 000000000..7801b94c1 --- /dev/null +++ b/lib/vagrant/command/up.rb @@ -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 diff --git a/test/vagrant/command/helpers_test.rb b/test/vagrant/command/helpers_test.rb index 606b269eb..21fbf6d43 100644 --- a/test/vagrant/command/helpers_test.rb +++ b/test/vagrant/command/helpers_test.rb @@ -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