fix support for multiple unique easy commands
This commit is contained in:
parent
4cc3fb05df
commit
2355a4b9a6
|
@ -5,26 +5,26 @@ module Vagrant
|
||||||
# Base class for all easy commands. This contains the basic code
|
# Base class for all easy commands. This contains the basic code
|
||||||
# that knows how to run the easy commands.
|
# that knows how to run the easy commands.
|
||||||
class CommandBase < Vagrant::Command::Base
|
class CommandBase < Vagrant::Command::Base
|
||||||
@@command = nil
|
@command = nil
|
||||||
@@runner = nil
|
@runner = nil
|
||||||
|
|
||||||
# This is called by the {EasyCommand.create} method when creating
|
# This is called by the {EasyCommand.create} method when creating
|
||||||
# an easy command to set the invocation command.
|
# an easy command to set the invocation command.
|
||||||
def self.configure(name, &block)
|
def self.configure(name, &block)
|
||||||
@@command = name
|
@command = name
|
||||||
@@runner = block
|
@runner = block
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*args, &block)
|
def initialize(*args, &block)
|
||||||
super
|
super
|
||||||
|
|
||||||
@logger = Log4r::Logger.new("vagrant::easy_command::#{@@command}")
|
@logger = Log4r::Logger.new("vagrant::easy_command::#{@command}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
# Build up a basic little option parser
|
# Build up a basic little option parser
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: vagrant #{@@command}"
|
opts.banner = "Usage: vagrant #{@command}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
|
@ -32,10 +32,10 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
# Run the action for each VM.
|
# Run the action for each VM.
|
||||||
@logger.info("Running easy command: #{@@command}")
|
@logger.info("Running easy command: #{@command}")
|
||||||
with_target_vms(argv) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
@logger.debug("Running easy command for VM: #{vm.name}")
|
@logger.debug("Running easy command for VM: #{vm.name}")
|
||||||
@@runner.call(Operations.new(vm))
|
@runner.call(Operations.new(vm))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit status 0 every time for now
|
# 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
|
# Check that the command class subclasses the easy command base
|
||||||
plugin.command[:foo].should < Vagrant::Easy::CommandBase
|
plugin.command[:foo].should < Vagrant::Easy::CommandBase
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "guests" do
|
describe "guests" do
|
||||||
|
|
Loading…
Reference in New Issue