mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-05-28 04:36:05 -04:00
Add a simple push plugin in Go
The only tweak required to get this to work was allowing a DummyConfig to survive being passed through a remote plugin on the Ruby side.
This commit is contained in:
parent
737c1a5f8b
commit
a841da4fc6
4 changed files with 40 additions and 0 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
23
builtin/myplugin/push/encouragement.go
Normal file
23
builtin/myplugin/push/encouragement.go
Normal file
|
|
@ -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)
|
||||
)
|
||||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue