Make host cap function call work with arguments
This commit is contained in:
parent
10673990c7
commit
a5b0642577
@ -27,7 +27,7 @@ func (h *AlwaysTrueHost) Detect() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *AlwaysTrueHost) InitializeCapabilities() (err error) {
|
func (h *AlwaysTrueHost) InitializeCapabilities() (err error) {
|
||||||
err = h.RegisterCapability("write_hello", cap.WriteHelloFunc())
|
err = h.RegisterCapability("write_hello", cap.WriteHello)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,15 +2,12 @@ package cap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteHelloFunc() interface{} {
|
func WriteHello(ui terminal.UI) error {
|
||||||
return WriteHello
|
data := []byte("Hello from the write hello capability, compliments of the AlwaysTrue Host")
|
||||||
}
|
|
||||||
|
|
||||||
// func WriteHello(trm terminal.UI) error {
|
|
||||||
func WriteHello() error {
|
|
||||||
data := []byte("hello from the always true host plugin\n")
|
|
||||||
ioutil.WriteFile("/tmp/hello", data, 0644)
|
ioutil.WriteFile("/tmp/hello", data, 0644)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -162,7 +162,11 @@ func (c *Command) ExecuteUseHostPlugin(trm terminal.UI, host plugincore.Host) in
|
|||||||
ok := host.HasCapability("write_hello")
|
ok := host.HasCapability("write_hello")
|
||||||
if ok {
|
if ok {
|
||||||
trm.Output("Writing to file using `write_hello` capability")
|
trm.Output("Writing to file using `write_hello` capability")
|
||||||
host.Capability("write_hello", argmapper.Typed(trm))
|
_, err := host.Capability("write_hello", argmapper.Typed("hehehe i'm a string"), argmapper.Typed(trm))
|
||||||
|
if err != nil {
|
||||||
|
trm.Output("Error!")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
trm.Output("no `write_hello` capability found")
|
trm.Output("no `write_hello` capability found")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/datadir"
|
"github.com/hashicorp/vagrant-plugin-sdk/datadir"
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/componentprotomappers"
|
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers"
|
"github.com/hashicorp/vagrant-plugin-sdk/internal-shared/protomappers"
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
|
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
|
||||||
@ -96,8 +95,7 @@ func NewBasis(ctx context.Context, opts ...BasisOption) (b *Basis, err error) {
|
|||||||
|
|
||||||
// If the mappers aren't already set, load known mappers
|
// If the mappers aren't already set, load known mappers
|
||||||
if len(b.mappers) == 0 {
|
if len(b.mappers) == 0 {
|
||||||
mappers := append(protomappers.All, componentprotomappers.All...)
|
b.mappers, err = argmapper.NewFuncList(protomappers.All,
|
||||||
b.mappers, err = argmapper.NewFuncList(mappers,
|
|
||||||
argmapper.Logger(b.logger),
|
argmapper.Logger(b.logger),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -168,6 +168,16 @@ func (t *Target) Run(ctx context.Context, task *vagrant_server.Task) (err error)
|
|||||||
|
|
||||||
host, _ := t.project.Host()
|
host, _ := t.project.Host()
|
||||||
|
|
||||||
|
_, err = t.callDynamicFunc(
|
||||||
|
ctx,
|
||||||
|
t.logger,
|
||||||
|
(interface{})(nil),
|
||||||
|
nil,
|
||||||
|
host.(component.Host).CapabilityFunc("write_hello"),
|
||||||
|
argmapper.Typed(t.ui),
|
||||||
|
)
|
||||||
|
// host.Capability("write_hello", argmapper.Typed(t.ui))
|
||||||
|
|
||||||
result, err := t.callDynamicFunc(
|
result, err := t.callDynamicFunc(
|
||||||
ctx,
|
ctx,
|
||||||
t.logger,
|
t.logger,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user