Setup builtin host plugin with capabilities

This commit is contained in:
sophia 2021-04-23 14:36:37 -05:00 committed by Paul Hinze
parent c6ad026070
commit 28dd174686
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package cap
import "io/ioutil"
func WriteHello() {
data := []byte("hello\ngo\n")
ioutil.WriteFile("/tmp/dat1", data, 0644)
}

View File

@ -0,0 +1,36 @@
package host
import (
"github.com/hashicorp/vagrant-plugin-sdk/component"
sdkcore "github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant/builtin/myplugin/host/cap"
)
type HostConfig struct {
}
// TestOSXHost is a Host implementation for myplugin.
type OSXHost struct {
config HostConfig
// Include capability host
sdkcore.CapabilityHost
}
// DetectFunc implements component.Host
func (h *OSXHost) DetectFunc() interface{} {
return h.Detect()
}
func (h *OSXHost) Detect() bool {
return true
}
func (h *OSXHost) InitializeCapabilities() {
h.RegisterCapability("write_hello", cap.WriteHello)
}
var (
_ component.Host = (*OSXHost)(nil)
_ sdkcore.Host = (*OSXHost)(nil)
)