fix support for multiple unique easy commands

This commit is contained in:
Ryan LeCompte 2012-05-06 01:47:43 -07:00
parent 4cc3fb05df
commit 2355a4b9a6
2 changed files with 18 additions and 8 deletions

View File

@ -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

View File

@ -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