diff --git a/builtin/myplugin/main.go b/builtin/myplugin/main.go index 950e42d8a..944d555db 100644 --- a/builtin/myplugin/main.go +++ b/builtin/myplugin/main.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/vagrant/builtin/myplugin/command" communincator "github.com/hashicorp/vagrant/builtin/myplugin/communicator" "github.com/hashicorp/vagrant/builtin/myplugin/host" + "github.com/hashicorp/vagrant/builtin/myplugin/push" ) //go:generate protoc -I ../../.. --go_opt=plugins=grpc --go_out=../../.. vagrant-ruby/builtin/myplugin/proto/plugin.proto @@ -16,6 +17,7 @@ var CommandOptions = []sdk.Option{ &command.Command{}, &host.AlwaysTrueHost{}, &communincator.DummyCommunicator{}, + &push.Encouragement{}, ), sdk.WithMappers(StructToCommunincatorOptions), sdk.WithName("myplugin"), diff --git a/builtin/myplugin/push/encouragement.go b/builtin/myplugin/push/encouragement.go new file mode 100644 index 000000000..d31baf1f6 --- /dev/null +++ b/builtin/myplugin/push/encouragement.go @@ -0,0 +1,23 @@ +package push + +import ( + "github.com/hashicorp/vagrant-plugin-sdk/component" + "github.com/hashicorp/vagrant-plugin-sdk/core" + "github.com/hashicorp/vagrant-plugin-sdk/terminal" +) + +// This is a push strategy that provides encouragement for the code you push +type Encouragement struct{} + +func (e *Encouragement) PushFunc() interface{} { + return e.Push +} + +func (e *Encouragement) Push(ui terminal.UI, proj core.Project) error { + ui.Output("You've invoked a push plugin written in Go! Great work!") + return nil +} + +var ( + _ component.Push = (*Encouragement)(nil) +) diff --git a/lib/vagrant/config/v2/dummy_config.rb b/lib/vagrant/config/v2/dummy_config.rb index 3c168acb4..031be0275 100644 --- a/lib/vagrant/config/v2/dummy_config.rb +++ b/lib/vagrant/config/v2/dummy_config.rb @@ -7,6 +7,14 @@ module Vagrant LOG = Log4r::Logger.new("vagrant::config::v2::dummy_config") def method_missing(name, *args, &block) + # If a DummyConfig ends up as a last arg in a situation where it's + # being passed through a method with *kwargs, ruby 2.x will try to + # implicitly convert it into a hash. If it responds to to_hash but + # does not return an actual hash, Ruby gets mad. + if name == :to_hash + return super + end + # Trying to define a variable if name.to_s.match(/^[\w]*=/) LOG.debug("found name #{name}") diff --git a/test/unit/vagrant/config/v2/dummy_config_test.rb b/test/unit/vagrant/config/v2/dummy_config_test.rb index 00c8dd13d..bf4a7bd16 100644 --- a/test/unit/vagrant/config/v2/dummy_config_test.rb +++ b/test/unit/vagrant/config/v2/dummy_config_test.rb @@ -21,4 +21,11 @@ describe Vagrant::Config::V2::DummyConfig do expect { subject[:foo] = :bar }. to_not raise_error end + + it "should survive being the last arg to a method that captures kwargs without a ruby conversion error" do + arg_capturer = lambda { |*args, **kwargs| } + expect { + arg_capturer.call(subject) + }.to_not raise_error + end end