Documentation
¶
Overview ¶
Package plugin implements dtctl's kubectl-style exec plugin convention: an executable named dtctl-<name> on PATH extends dtctl with the `dtctl <name>` command. This package only resolves and discovers plugins; dispatch (the exec) lives in cmd, and built-in commands always win because dispatch is only attempted for names cobra does not know.
See docs/dev/PLUGIN_CONVENTIONS.md for the author-facing contract.
Index ¶
Constants ¶
const Prefix = "dtctl-"
Prefix is the file-name prefix that marks an executable as a dtctl plugin.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Invocation ¶
type Invocation struct {
// CommandWords are the argv words consumed by the plugin name,
// e.g. ["foo", "bar"] for dtctl-foo-bar.
CommandWords []string
// Path is the resolved binary path.
Path string
// Args are the remaining arguments to pass to the plugin.
Args []string
}
Invocation is a resolved plugin call.
func Resolve ¶
Resolve maps leading command words to the longest matching dtctl-<a-b-c> binary on PATH (kubectl semantics): words [foo bar baz] tries dtctl-foo-bar-baz, then dtctl-foo-bar (arg baz), then dtctl-foo (args bar baz). rest is appended after the unconsumed words. lookPath is exec.LookPath in production; injected for tests.
A candidate name containing a path separator is never looked up: a separator would turn the name into a relative path, and exec.LookPath resolves those against the working directory without the ErrDot guard that otherwise keeps dispatch off cwd-relative binaries. Shorter separator-free prefixes still resolve, so a path may appear as a plugin argument (`dtctl foo some/file.yaml`), just never in the plugin name.
type Plugin ¶
type Plugin struct {
Name string `json:"name" yaml:"name" table:"NAME"`
Binary string `json:"binary" yaml:"binary" table:"BINARY"`
Path string `json:"path" yaml:"path" table:"PATH"`
Warning string `json:"warning,omitempty" yaml:"warning,omitempty" table:"WARNING"`
}
Plugin is a plugin binary discovered on PATH.
func Discover ¶
Discover scans the directories of pathEnv (a PATH-formatted list) for dtctl-* executables. The first occurrence of a binary name on PATH wins, matching exec semantics. builtins is the set of built-in dtctl command names (including aliases); a plugin whose first command word collides gets a Warning, because built-ins always win at dispatch time.