diff --git a/plugins/commands/cap/command.rb b/plugins/commands/cap/command.rb index 43a80cfb5..bd3908a7a 100644 --- a/plugins/commands/cap/command.rb +++ b/plugins/commands/cap/command.rb @@ -27,6 +27,10 @@ module VagrantPlugins o.on("--check", "Only checks for a capability, does not execute") do |f| options[:check] = f end + + o.on("-t", "--target=TARGET", "Target guest to run against (if applicable)") do |t| + options[:target] = t + end end # Parse the options @@ -45,7 +49,7 @@ module VagrantPlugins if type == :host cap_host = @env.host else - with_target_vms([]) do |vm| + with_target_vms(options[:target] || []) do |vm| cap_host = case type when :provider vm.provider diff --git a/test/unit/plugins/commands/cap/command_test.rb b/test/unit/plugins/commands/cap/command_test.rb index 9e3394fec..acb32f5ad 100644 --- a/test/unit/plugins/commands/cap/command_test.rb +++ b/test/unit/plugins/commands/cap/command_test.rb @@ -47,5 +47,26 @@ describe VagrantPlugins::CommandCap::Command do expect(subject.execute).to eq(1) end end + + context "runs against target vm" do + let(:argv) { ["provider", "foo", "--target=dummy"] } + let(:cap) { + Class.new do + def self.foo(m) + true + end + end + } + + before do + register_plugin do |p| + p.provider_capability(:dummy, :foo) { cap } + end + end + + it "exits with 0 if it exists" do + expect(subject.execute).to eq(0) + end + end end end