Command helpers `target_vms` now takes an optional string for the VM name
This commit is contained in:
parent
d5fbf29ec0
commit
90aaf5cb5e
|
@ -11,14 +11,16 @@ module Vagrant
|
|||
|
||||
# This returns an array of {VM} objects depending on the arguments
|
||||
# given to the command.
|
||||
def target_vms
|
||||
def target_vms(name=nil)
|
||||
name ||= self.name
|
||||
|
||||
@target_vms ||= begin
|
||||
if env.multivm?
|
||||
return env.vms.values if !self.name
|
||||
vm = env.vms[self.name.to_sym]
|
||||
raise Errors::VMNotFoundError.new(:name => self.name) if !vm
|
||||
return env.vms.values if !name
|
||||
vm = env.vms[name.to_sym]
|
||||
raise Errors::VMNotFoundError.new(:name => name) if !vm
|
||||
else
|
||||
raise Errors::MultiVMEnvironmentRequired.new if self.name
|
||||
raise Errors::MultiVMEnvironmentRequired.new if name
|
||||
vm = env.vms.values.first
|
||||
end
|
||||
|
||||
|
|
|
@ -71,6 +71,11 @@ class CommandHelpersTest < Test::Unit::TestCase
|
|||
assert_equal @env.vms[:one], instance.target_vms.first
|
||||
end
|
||||
|
||||
should "return only the specified VM if name is given in the arg" do
|
||||
instance = command([], @env)
|
||||
assert_equal @env.vms[:two], instance.target_vms("two").first
|
||||
end
|
||||
|
||||
should "raise an exception if an invalid name is given" do
|
||||
instance = command(["foo"], @env)
|
||||
assert_raises(Vagrant::Errors::VMNotFoundError) {
|
||||
|
|
Loading…
Reference in New Issue