From a8f5ed1863d3c37853c69c23375c9fd8d9f7c846 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 18 Dec 2011 13:26:15 -0800 Subject: [PATCH] Require vagrant environments for some commands. --- lib/vagrant/command/base.rb | 3 +++ templates/locales/en.yml | 5 +++-- test/acceptance/support/output.rb | 2 +- test/unit/vagrant/command/base_test.rb | 14 +++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/command/base.rb b/lib/vagrant/command/base.rb index 1ad566c21..332a21da8 100644 --- a/lib/vagrant/command/base.rb +++ b/lib/vagrant/command/base.rb @@ -60,6 +60,9 @@ module Vagrant # # @param [String] name The name of the VM. Nil if every VM. def with_target_vms(name=nil) + # Using VMs requires a Vagrant environment to be properly setup + raise Errors::NoEnvironmentError if !@env.root_path + # First determine the proper array of VMs. vms = [] if name diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 23d003c49..60afa7fca 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -26,7 +26,6 @@ en: puppetd_not_detected: |- The `puppetd` binary was not found on the VM is required for Puppet Server provisioning. Please verify that Puppet is installed and that the binary is available on the PATH. - cli_missing_env: This command requires that a Vagrant environment be properly passed in as the last parameter. config_validation: |- There was a problem with the configuration of Vagrant. The error message(s) are printed below: @@ -63,7 +62,9 @@ en: interrupted: "Vagrant exited after cleanup due to external interrupt." multi_vm_required: "A multi-vm environment is required for name specification to this command." multi_vm_target_required: "`vagrant %{command}` requires a specific VM name to target in a multi-VM environment." - no_env: "No Vagrant environment detected. Run `vagrant init` to set one up." + no_env: |- + A Vagrant environment is required to run this command. Run `vagrant init` + to set one up. scp_unavailable: |- SSH server on the guest doesn't support SCP. Please install the necessary software to enable SCP on your guest operating system. diff --git a/test/acceptance/support/output.rb b/test/acceptance/support/output.rb index 75a3f2d6c..e317e32f7 100644 --- a/test/acceptance/support/output.rb +++ b/test/acceptance/support/output.rb @@ -33,7 +33,7 @@ module Acceptance # Tests that the output says there is no Vagrantfile, and as such # can't do whatever we requested Vagrant to do. def no_vagrantfile - @text =~ /^No Vagrant environment detected/ + @text =~ /^A Vagrant environment is required/ end # Tests that the output contains a specific Vagrant version. diff --git a/test/unit/vagrant/command/base_test.rb b/test/unit/vagrant/command/base_test.rb index caa716e67..1088a2de1 100644 --- a/test/unit/vagrant/command/base_test.rb +++ b/test/unit/vagrant/command/base_test.rb @@ -53,9 +53,21 @@ describe Vagrant::Command::Base do end end - let(:environment) { double("environment") } + let(:environment) do + env = double("environment") + env.stub(:root_path => "foo") + env + end + let(:instance) { klass.new([], environment) } + it "should raise an exception if a root_path is not available" do + environment.stub(:root_path => nil) + + expect { instance.with_target_vms }. + to raise_error(Vagrant::Errors::NoEnvironmentError) + end + it "should raise an exception if a name is given in a non-multivm environment" do environment.stub(:multivm?).and_return(false)