From 8340472fc5c75ce726d87250bf5943eb7544c299 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Aug 2010 23:03:37 -0700 Subject: [PATCH] `vagrant up` --- lib/vagrant/command/helpers.rb | 6 ++++++ lib/vagrant/command/status.rb | 5 +---- lib/vagrant/command/up.rb | 23 +++++++++++++++++++++++ test/vagrant/command/helpers_test.rb | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 lib/vagrant/command/up.rb 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