Require vagrant environments for some commands.

This commit is contained in:
Mitchell Hashimoto 2011-12-18 13:26:15 -08:00
parent a5052131df
commit a8f5ed1863
4 changed files with 20 additions and 4 deletions

View File

@ -60,6 +60,9 @@ module Vagrant
# #
# @param [String] name The name of the VM. Nil if every VM. # @param [String] name The name of the VM. Nil if every VM.
def with_target_vms(name=nil) 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. # First determine the proper array of VMs.
vms = [] vms = []
if name if name

View File

@ -26,7 +26,6 @@ en:
puppetd_not_detected: |- puppetd_not_detected: |-
The `puppetd` binary was not found on the VM is required for Puppet Server provisioning. 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. 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: |- config_validation: |-
There was a problem with the configuration of Vagrant. The error message(s) There was a problem with the configuration of Vagrant. The error message(s)
are printed below: are printed below:
@ -63,7 +62,9 @@ en:
interrupted: "Vagrant exited after cleanup due to external interrupt." 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_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." 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: |- scp_unavailable: |-
SSH server on the guest doesn't support SCP. Please install the necessary SSH server on the guest doesn't support SCP. Please install the necessary
software to enable SCP on your guest operating system. software to enable SCP on your guest operating system.

View File

@ -33,7 +33,7 @@ module Acceptance
# Tests that the output says there is no Vagrantfile, and as such # Tests that the output says there is no Vagrantfile, and as such
# can't do whatever we requested Vagrant to do. # can't do whatever we requested Vagrant to do.
def no_vagrantfile def no_vagrantfile
@text =~ /^No Vagrant environment detected/ @text =~ /^A Vagrant environment is required/
end end
# Tests that the output contains a specific Vagrant version. # Tests that the output contains a specific Vagrant version.

View File

@ -53,9 +53,21 @@ describe Vagrant::Command::Base do
end end
end end
let(:environment) { double("environment") } let(:environment) do
env = double("environment")
env.stub(:root_path => "foo")
env
end
let(:instance) { klass.new([], environment) } 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 it "should raise an exception if a name is given in a non-multivm environment" do
environment.stub(:multivm?).and_return(false) environment.stub(:multivm?).and_return(false)