Merge pull request #915 from ryanlecompte/master
Fix support for multiple unique easy commands
This commit is contained in:
commit
63ed57e880
|
@ -5,26 +5,26 @@ module Vagrant
|
|||
# Base class for all easy commands. This contains the basic code
|
||||
# that knows how to run the easy commands.
|
||||
class CommandBase < Vagrant::Command::Base
|
||||
@@command = nil
|
||||
@@runner = nil
|
||||
@command = nil
|
||||
@runner = nil
|
||||
|
||||
# This is called by the {EasyCommand.create} method when creating
|
||||
# an easy command to set the invocation command.
|
||||
def self.configure(name, &block)
|
||||
@@command = name
|
||||
@@runner = block
|
||||
@command = name
|
||||
@runner = block
|
||||
end
|
||||
|
||||
def initialize(*args, &block)
|
||||
super
|
||||
|
||||
@logger = Log4r::Logger.new("vagrant::easy_command::#{@@command}")
|
||||
@logger = Log4r::Logger.new("vagrant::easy_command::#{@command}")
|
||||
end
|
||||
|
||||
def execute
|
||||
# Build up a basic little option parser
|
||||
opts = OptionParser.new do |opts|
|
||||
opts.banner = "Usage: vagrant #{@@command}"
|
||||
opts.banner = "Usage: vagrant #{@command}"
|
||||
end
|
||||
|
||||
# Parse the options
|
||||
|
@ -32,10 +32,10 @@ module Vagrant
|
|||
return if !argv
|
||||
|
||||
# Run the action for each VM.
|
||||
@logger.info("Running easy command: #{@@command}")
|
||||
@logger.info("Running easy command: #{@command}")
|
||||
with_target_vms(argv) do |vm|
|
||||
@logger.debug("Running easy command for VM: #{vm.name}")
|
||||
@@runner.call(Operations.new(vm))
|
||||
@runner.call(Operations.new(vm))
|
||||
end
|
||||
|
||||
# Exit status 0 every time for now
|
||||
|
|
|
@ -109,6 +109,16 @@ describe Vagrant::Plugin::V1 do
|
|||
# Check that the command class subclasses the easy command base
|
||||
plugin.command[:foo].should < Vagrant::Easy::CommandBase
|
||||
end
|
||||
|
||||
it "should support registering multiple unique commands" do
|
||||
plugins = %w(foo bar baz).map do |cmd|
|
||||
[cmd, Vagrant::Easy.create_command(cmd)]
|
||||
end
|
||||
|
||||
plugins.each do |cmd, plugin|
|
||||
plugin.instance_variable_get(:@command).should == cmd
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "guests" do
|
||||
|
|
Loading…
Reference in New Issue