Add parents function and remove extras

This commit is contained in:
Chris Roberts 2021-07-20 15:49:39 -07:00 committed by Paul Hinze
parent ad2ad1d9df
commit 131e11a8a8
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 11 additions and 16 deletions

View File

@ -4,7 +4,6 @@ import (
"errors"
"github.com/hashicorp/vagrant-plugin-sdk/component"
// "github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
"github.com/hashicorp/vagrant/builtin/myplugin/host/cap"
)
@ -26,6 +25,16 @@ func (h *AlwaysTrueHost) Detect() bool {
return true
}
// ParentsFunc implements component.Host
func (h *AlwaysTrueHost) ParentsFunc() interface{} {
return h.Parents
}
func (h *AlwaysTrueHost) Parents() []string {
return []string{"force", "host", "platform", "match"} // We just need to have this be the most of all matches
}
// HasCapabilityFunc implements component.Host
func (h *AlwaysTrueHost) HasCapabilityFunc() interface{} {
return h.CheckCapability
}
@ -37,6 +46,7 @@ func (h *AlwaysTrueHost) CheckCapability(n *component.NamedCapability) bool {
return false
}
// CapabilityFunc implements component.Host
func (h *AlwaysTrueHost) CapabilityFunc(name string) interface{} {
if name == "write_hello" {
return h.WriteHelloCap
@ -48,10 +58,6 @@ func (h *AlwaysTrueHost) WriteHelloCap(ui terminal.UI) error {
return cap.WriteHello(ui)
}
func (h *AlwaysTrueHost) WriteHelloCapNoUI() error {
return cap.WriteHelloNoUI()
}
var (
_ component.Host = (*AlwaysTrueHost)(nil)
)

View File

@ -1,22 +1,11 @@
package cap
import (
"io/ioutil"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
)
func WriteHello(ui terminal.UI) error {
msg := "Hello from the write hello capability, compliments of the AlwaysTrue Host"
ui.Output(msg)
data := []byte(msg)
ioutil.WriteFile("/tmp/hello", data, 0644)
return nil
}
func WriteHelloNoUI() error {
msg := "Hello from the write hello capability, compliments of the AlwaysTrue Host"
data := []byte(msg)
ioutil.WriteFile("/tmp/hello", data, 0644)
return nil
}