plugin

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KnTestPluginName   = "kn-test"
	KnTestPluginScript = `#!/bin/bash

echo "I am a test Kn plugin"
exit 0
`
	FileModeReadable   = 0644
	FileModeExecutable = 0777
)
View Source
const (
	UserExecute  = 1 << 6
	GroupExecute = 1 << 3
	OtherExecute = 1 << 0
)

permission bits for execute

Variables

View Source
var ValidPluginFilenamePrefixes = []string{"kn"}

ValidPluginFilenamePrefixes controls the prefix for all kn plugins

Functions

func AddPluginFlags

func AddPluginFlags(cmd *cobra.Command)

AddPluginFlags plugins-dir and lookup-plugins to cmd

func BindPluginsFlagToViper

func BindPluginsFlagToViper(cmd *cobra.Command)

BindPluginsFlagToViper bind and set default with viper for plugins flags

func CreateTestPlugin

func CreateTestPlugin(t *testing.T, name, script string, fileMode os.FileMode) string

CreateTestPlugin with name, script, and fileMode and return the tmp random path

func CreateTestPluginInPath

func CreateTestPluginInPath(t *testing.T, name, script string, fileMode os.FileMode, path string) string

CreateTestPluginInPath with name, path, script, and fileMode and return the tmp random path

func DeleteTestPlugin

func DeleteTestPlugin(t *testing.T, path string)

DeleteTestPlugin with path

func FindSubCommand

func FindSubCommand(t *testing.T, rootCmd *cobra.Command, name string) *cobra.Command

FindSubCommand return the sub-command by name

func HandlePluginCommand

func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error

HandlePluginCommand receives a pluginHandler and command-line arguments and attempts to find a plugin executable that satisfies the given arguments.

func NewPluginCommand

func NewPluginCommand(p *commands.KnParams) *cobra.Command

func NewPluginListCommand

func NewPluginListCommand(p *commands.KnParams) *cobra.Command

NewPluginListCommand creates a new `kn plugin list` command

Types

type DefaultPluginHandler

type DefaultPluginHandler struct {
	ValidPrefixes       []string
	PluginsDir          string
	LookupPluginsInPath bool
}

DefaultPluginHandler implements PluginHandler

func NewDefaultPluginHandler

func NewDefaultPluginHandler(validPrefixes []string, pluginsDir string, lookupPluginsInPath bool) *DefaultPluginHandler

NewDefaultPluginHandler instantiates the DefaultPluginHandler with a list of given filename prefixes used to identify valid plugin filenames.

func (*DefaultPluginHandler) Execute

func (h *DefaultPluginHandler) Execute(executablePath string, cmdArgs, environment []string) error

Execute implements PluginHandler

func (*DefaultPluginHandler) Lookup

func (h *DefaultPluginHandler) Lookup(name string) (string, bool)

Lookup implements PluginHandler TODO: The current error handling is not optimal, and some errors may be lost. We should refactor the code in the future.

type PluginHandler

type PluginHandler interface {
	// exists at the given filename, or a boolean false.
	// Lookup will iterate over a list of given prefixes
	// in order to recognize valid plugin filenames.
	// The first filepath to match a prefix is returned.
	Lookup(name string) (string, bool)
	// Execute receives an executable's filepath, a slice
	// of arguments, and a slice of environment variables
	// to relay to the executable.
	Execute(executablePath string, cmdArgs, environment []string) error
}

PluginHandler is capable of parsing command line arguments and performing executable filename lookups to search for valid plugin files, and execute found plugins.

Jump to

Keyboard shortcuts

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