Documentation
¶
Index ¶
- Constants
- Variables
- func AddPluginFlags(cmd *cobra.Command)
- func BindPluginsFlagToViper(cmd *cobra.Command)
- func CreateTestPlugin(t *testing.T, name, script string, fileMode os.FileMode) string
- func CreateTestPluginInPath(t *testing.T, name, script string, fileMode os.FileMode, path string) string
- func DeleteTestPlugin(t *testing.T, path string)
- func FindSubCommand(t *testing.T, rootCmd *cobra.Command, name string) *cobra.Command
- func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error
- func NewPluginCommand(p *commands.KnParams) *cobra.Command
- func NewPluginListCommand(p *commands.KnParams) *cobra.Command
- type DefaultPluginHandler
- type PluginHandler
Constants ¶
const ( KnTestPluginName = "kn-test" KnTestPluginScript = `#!/bin/bash echo "I am a test Kn plugin" exit 0 ` FileModeReadable = 0644 FileModeExecutable = 0777 )
const ( UserExecute = 1 << 6 GroupExecute = 1 << 3 OtherExecute = 1 << 0 )
permission bits for execute
Variables ¶
var ValidPluginFilenamePrefixes = []string{"kn"}
ValidPluginFilenamePrefixes controls the prefix for all kn plugins
Functions ¶
func AddPluginFlags ¶
AddPluginFlags plugins-dir and lookup-plugins to cmd
func BindPluginsFlagToViper ¶
BindPluginsFlagToViper bind and set default with viper for plugins flags
func CreateTestPlugin ¶
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 FindSubCommand ¶
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.
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.
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.