Documentation
¶
Overview ¶
Package plugin is the SDK for writing orca plugins in Go.
A plugin is a standalone binary named orca-plugin-<name>, placed in one of orca's plugin directories. Its main function only needs to call Serve with an implementation of CommandProvider:
func main() {
plugin.Serve(&myProvider{})
}
Index ¶
Constants ¶
const CommandsPluginName = "commands"
CommandsPluginName is the name the CommandProvider is dispensed under.
Variables ¶
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "ORCA_PLUGIN",
MagicCookieValue: "4b0a1d6e-2f53-4c4e-9a52-7a1f6c1d2e83",
}
Handshake must match between orca and its plugins. Bump ProtocolVersion on any breaking change to the gRPC protocol.
var PluginMap = map[string]goplugin.Plugin{ CommandsPluginName: &CommandProviderPlugin{}, }
PluginMap is the set of plugin types orca can dispense from a plugin binary.
Functions ¶
func Serve ¶
func Serve(impl CommandProvider)
Serve starts the plugin's gRPC server and blocks until orca disconnects. It should be the only thing a plugin's main function does.
Types ¶
type CommandProvider ¶
type CommandProvider interface {
// Commands returns the command tree to register with orca.
Commands() ([]CommandSpec, error)
// Execute runs one of the commands returned by Commands. Anything written to
// stdout/stderr is forwarded to the user's terminal.
Execute(ctx context.Context, req ExecuteRequest) (exitCode int, err error)
}
CommandProvider is implemented by plugins that contribute CLI commands to orca.
type CommandProviderPlugin ¶
type CommandProviderPlugin struct {
goplugin.NetRPCUnsupportedPlugin
Impl CommandProvider
}
CommandProviderPlugin wires a CommandProvider into go-plugin over gRPC. Impl is only set on the plugin side.
func (*CommandProviderPlugin) GRPCClient ¶
func (p *CommandProviderPlugin) GRPCClient(_ context.Context, _ *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)
func (*CommandProviderPlugin) GRPCServer ¶
func (p *CommandProviderPlugin) GRPCServer(_ *goplugin.GRPCBroker, s *grpc.Server) error
type CommandSpec ¶
type CommandSpec struct {
// Use is the one-line usage message, the first word is the command name.
Use string
Short string
Long string
Flags []FlagSpec
Subcommands []CommandSpec
}
type ExecuteRequest ¶
type ExecuteRequest struct {
// CommandPath is the names of the commands from the plugin's top-level
// command down to the one being executed, e.g. ["k8s", "ctx"].
CommandPath []string
Args []string
// Flags holds every flag value for the command keyed by name, encoded as
// strings.
Flags map[string]string
}