...

Package plugins

Overview ▾

func HandleCommand

func HandleCommand(handler PluginHandler, args []string) error

HandleCommand receives a PluginHandler and command-line arguments and attempts to find a plugin executable on the PATH that satisfies the given arguments.

type ExecHandler

ExecHandler implements PluginHandler using the "os/exec" package.

type ExecHandler struct {
    Prefix string
    Exec   execFunc
}

func NewExecHandler

func NewExecHandler(prefix string) *ExecHandler

NewExecHandler creates and returns a new ExecHandler configured with the prefix.

func (*ExecHandler) Execute

func (h *ExecHandler) Execute(filename string, args, env []string) error

Execute implements PluginHandler.Execute

func (*ExecHandler) Lookup

func (h *ExecHandler) Lookup(command string) string

Lookup implements PluginHandler, using https://golang.org/pkg/os/exec/#LookPath to search for the command.

type PluginHandler

PluginHandler provides functionality for finding and executing external plugins.

type PluginHandler interface {
    // Lookup should return the full path to an executable for the provided
    // command, or "" if no matching command can be found.
    Lookup(command string) string

    // Execute should execute the provided path, passing in the args and env.
    Execute(filename string, args, env []string) error
}