plugin

package
v0.0.0-...-7f57805 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFilename = "plugin.yaml"

DefaultFilename is the filename for the plugin metadata

Variables

View Source
var ErrNotAGoPlugin = errors.New("not a Go plugin")

ErrNotAGoPlugin is returned when attempting to load a file that's not a Go plugin

Functions

This section is empty.

Types

type Command

type Command struct {
	Base string
	Args []string
}

Command is a parsed plugin command

func (*Command) UnmarshalYAML

func (c *Command) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml unmarshaller interface This function deconstructs the command to base command and args

type DefaultHandler

type DefaultHandler struct {
	Dir      string
	Filename string
}

DefaultHandler is the default plugin handler

func (*DefaultHandler) GetPlugins

func (h *DefaultHandler) GetPlugins() ([]*Plugin, error)

GetPlugins returns all installed plugins found in the plugins directory

func (*DefaultHandler) InstallPlugin

func (h *DefaultHandler) InstallPlugin(path string) error

InstallPlugin creates a symlink from the specified directory to the plugins directory

func (*DefaultHandler) LoadGoPlugin

func (h *DefaultHandler) LoadGoPlugin(path string, settings *environment.Settings) (*cobra.Command, error)

LoadGoPlugin loads a cobra.Command from the Go plugin at the given path. The Go plugin must implement a command factory as follows:

	func New(settings *environment.Settings) *cobra.Command {
		return &cobra.Command{...}
 }

If the file at the given path is not a Go plugin then the error, ErrNotAGoPlugin, is returned. If the Go plugin does not implement the command factory then an error is returned.

func (*DefaultHandler) UninstallPlugin

func (h *DefaultHandler) UninstallPlugin(name string) error

UninstallPlugin removes the symlink from the plugin directory by plugin name

type Handler

type Handler interface {
	GetPlugins() ([]*Plugin, error)
	InstallPlugin(path string) error
	UninstallPlugin(name string) error
	LoadGoPlugin(path string, settings *environment.Settings) (*cobra.Command, error)
}

Handler defines the required actions for managing plugins

type Plugin

type Plugin struct {
	Name        string   `yaml:"name"`
	Usage       string   `yaml:"usage"`
	Description string   `yaml:"description"`
	Command     *Command `yaml:"command"`

	Path string `yaml:"-"`
}

Plugin is an installed, third-party command Consider using "github.com/mitchellh/mapstructure" when the yaml structure gets more complex

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL