plugins

package
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package plugins loads user-defined commands from a small YAML file, letting d9c be extended with custom actions (like k9s plugins). Each plugin binds a name (invoked as ":name") and/or a key to a local command, scoped to a resource view, with ${PLACEHOLDER} substitution from the selected row.

Example d9c-plugins.yaml:

plugins:
  - name: dive
    key: ctrl+d
    scope: images
    description: Explore image layers with dive
    command: dive
    args: ["${ID}"]
  - name: htop
    scope: containers
    command: docker
    args: ["-H", "${HOST}", "exec", "-it", "${ID}", "htop"]
  - name: df
    scope: "*"
    background: true          # stream output to the console instead of a TTY
    command: docker
    args: ["-H", "${HOST}", "system", "df"]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the plugins file location next to the running binary, falling back to the current directory if the executable path is unavailable.

func Substitute

func Substitute(p Plugin, vars map[string]string) (command string, args []string)

Substitute expands ${VAR} placeholders in the plugin's command and args using vars; unknown placeholders are left untouched so typos stay visible.

Types

type Plugin

type Plugin struct {
	Name        string   `yaml:"name"`
	Key         string   `yaml:"key"`
	Scope       string   `yaml:"scope"` // containers|images|networks|volumes|compose|hosts|* (default *)
	Description string   `yaml:"description"`
	Command     string   `yaml:"command"`
	Args        []string `yaml:"args"`
	// Background runs the command detached, streaming its output to the operation
	// console; the default (false) hands the terminal over for an interactive TTY.
	Background bool `yaml:"background"`
}

Plugin is a single user-defined action.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is an immutable collection of loaded plugins. All methods are nil-safe so callers can hold a nil *Set when no plugins are configured.

func Load

func Load(path string) (*Set, error)

Load reads and validates the plugins file at path. A missing file yields an empty set (not an error); malformed YAML or an invalid plugin is an error.

func New

func New(ps []Plugin) *Set

New builds a Set directly from already-validated plugins. Load is the usual entry point; New is handy for tests and programmatic configuration.

func (*Set) All

func (s *Set) All() []Plugin

All returns every loaded plugin.

func (*Set) ByKey

func (s *Set) ByKey(scope, key string) (Plugin, bool)

ByKey finds a plugin bound to key in the given scope.

func (*Set) ForScope

func (s *Set) ForScope(scope string) []Plugin

ForScope returns the plugins applicable in the given resource view (its own scope plus the wildcard "*").

func (*Set) Lookup

func (s *Set) Lookup(scope, name string) (Plugin, bool)

Lookup finds a plugin by name applicable in the given scope.

Jump to

Keyboard shortcuts

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