Add write_hello_file capability

This commit is contained in:
sophia 2021-10-18 11:55:31 -05:00 committed by Paul Hinze
parent ee7971ab1c
commit 7e3d2faa07
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 20 additions and 3 deletions

View File

@ -30,7 +30,7 @@ func (h *AlwaysTrueHost) HostDetectFunc() interface{} {
}
func (h *AlwaysTrueHost) Detect() bool {
return false
return true
}
// ParentsFunc implements component.Host
@ -39,7 +39,7 @@ func (h *AlwaysTrueHost) ParentsFunc() interface{} {
}
func (h *AlwaysTrueHost) Parents() []string {
return []string{"darwin", "bsd"}
return []string{}
}
// HasCapabilityFunc implements component.Host
@ -48,7 +48,7 @@ func (h *AlwaysTrueHost) HasCapabilityFunc() interface{} {
}
func (h *AlwaysTrueHost) CheckCapability(n *component.NamedCapability) bool {
if n.Capability == "write_hello" {
if n.Capability == "write_hello" || n.Capability == "write_hello_file" {
return true
}
return false
@ -58,6 +58,8 @@ func (h *AlwaysTrueHost) CheckCapability(n *component.NamedCapability) bool {
func (h *AlwaysTrueHost) CapabilityFunc(name string) interface{} {
if name == "write_hello" {
return h.WriteHelloCap
} else if name == "write_hello_file" {
return h.WriteHelloToTempFileCap
}
return errors.New("Invalid capability requested")
}
@ -66,6 +68,10 @@ func (h *AlwaysTrueHost) WriteHelloCap(ui terminal.UI) error {
return cap.WriteHello(ui)
}
func (h *AlwaysTrueHost) WriteHelloToTempFileCap() error {
return cap.WriteHelloToTempfile()
}
var (
_ component.Host = (*AlwaysTrueHost)(nil)
)

View File

@ -1,6 +1,8 @@
package cap
import (
"os"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
)
@ -9,3 +11,12 @@ func WriteHello(ui terminal.UI) error {
ui.Output(msg)
return nil
}
func WriteHelloToTempfile() error {
msg := []byte("Hello from the write hello capability, compliments of the AlwaysTrue Host")
err := os.WriteFile("/tmp/write_hello", msg, 0644)
if err != nil {
panic(err)
}
return nil
}