cmd

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 24 Imported by: 24

Documentation

Overview

Package cmd defines the concrete protocol between host and plugins based on libVeinMind plugin system.

Each plugins by themselves are standalone programs that can be run individually, but they must conform to some protocol between them and their host program if they want to produce meaningful output that can be interpreted and handled.

The plugins' command line layout should form a directory hierarchy with with an info command on the root. The info command reflects callable subcommands in the plugin, providing information and constrains of each subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContainerCommand added in v1.2.0

func AddContainerCommand(
	c *Command, f ContainerHandler,
)

AddContainerCommand issues defaultIndex.AddContainerCommand.

func AddContainerIDsCommand added in v1.2.0

func AddContainerIDsCommand(
	c *Command, f ContainerIDsHandler,
)

AddContainerCommand issues defaultIndex.AddContainerIDsCommand.

func AddImageCommand

func AddImageCommand(
	c *Command, f ImageHandler,
)

AddImageCommand issues defaultIndex.AddImageCommand.

func AddImageIDsCommand added in v1.1.0

func AddImageIDsCommand(
	c *Command, f ImageIDsHandler,
)

AddImageCommand issues defaultIndex.AddImageIDsCommand.

func AddModeCommand

func AddModeCommand(
	c *Command, typ string, obj interface{}, f ModeHandler,
)

MapModeCommand issues defaultIndex.AddModeCommand.

func AddPluginCommand

func AddPluginCommand(
	c *Command, typ string, obj interface{}, f PluginHandler,
)

AddPluginCommand invokes defaultIndex.AddPluginCommand.

func AddRuntimeCommand

func AddRuntimeCommand(
	c *Command, f RuntimeHandler,
)

AddRuntimeCommand issues defaultIndex.AddRuntimeCommand.

func Execute

func Execute()

Execute calls the ExecuteE and exit with code on error.

func ExecuteContext

func ExecuteContext(ctx context.Context)

ExecuteContext calls the ExecuteContextE and exits with code on error.

func ExecuteContextE

func ExecuteContextE(ctx context.Context) error

ExecuteContextE executes the auto-generated main command with context.

func ExecuteE

func ExecuteE() error

ExecuteE executes the auto-generated main command.

func IncompatibleMode

func IncompatibleMode() error

IncompatibleMode is the helper for reporting the user specified mode is not compatible with the command.

func RegisterMode

func RegisterMode(mode Mode)

RegisterMode to be used in subcommands.

func RegisterPartition

func RegisterPartition(f Partitioner)

func Scan

func Scan(
	ctx context.Context, iter plugin.ExecIterator,
	objs interface{}, opts ...plugin.ExecOption,
) error

Scan attempt to partition the objects and invoke plugin commands by itering the exec iterator.

func ScanAllContainers added in v1.2.0

func ScanAllContainers(
	ctx context.Context, rang plugin.ExecRange,
	runtime []api.Runtime, opts ...plugin.ExecOption,
) error

ScanAllContainers scans container provided by runtime list.

func ScanAllImages

func ScanAllImages(
	ctx context.Context, rang plugin.ExecRange,
	runtime []api.Runtime, opts ...plugin.ExecOption,
) error

ScanAllImages scans image provided by runtime list.

func ScanClusters added in v1.3.0

func ScanClusters(
	ctx context.Context, rang plugin.ExecRange,
	cluster []api.Cluster, opts ...plugin.ExecOption,
) error

ScanClusters scans cluster list.

func ScanContainer added in v1.2.0

func ScanContainer(
	ctx context.Context, rang plugin.ExecRange,
	container api.Container, opts ...plugin.ExecOption,
) error

ScanContainer scan an container provided.

func ScanContainerIDs added in v1.2.0

func ScanContainerIDs(
	ctx context.Context, rang plugin.ExecRange,
	runtime api.Runtime, ids []string, opts ...plugin.ExecOption,
) error

ScanContainerIDs with a runtime and a list of IDs provided.

func ScanContainers added in v1.2.0

func ScanContainers(
	ctx context.Context, rang plugin.ExecRange,
	containers []api.Container, opts ...plugin.ExecOption,
) error

ScanContainers scans container provided by container list.

func ScanIAC added in v1.3.2

func ScanIAC(
	ctx context.Context, rang plugin.ExecRange,
	IAC iac.IAC, opts ...plugin.ExecOption,
) error

ScanIAC scans iac provided by iac.

func ScanIACs added in v1.3.2

func ScanIACs(
	ctx context.Context, rang plugin.ExecRange,
	IACs []iac.IAC, opts ...plugin.ExecOption,
) error

ScanIACs scans iac provided by iac list.

func ScanIDs added in v1.0.7

func ScanIDs(
	ctx context.Context, iter plugin.ExecIterator,
	obj interface{}, ids []string, opts ...plugin.ExecOption,
) error

ScanIDs attempts to load a root object while passing a list of IDs that will be acceptable.

func ScanImage

func ScanImage(
	ctx context.Context, rang plugin.ExecRange,
	image api.Image, opts ...plugin.ExecOption,
) error

ScanImage scan an image provided.

func ScanImageIDs added in v1.0.7

func ScanImageIDs(
	ctx context.Context, rang plugin.ExecRange,
	runtime api.Runtime, ids []string, opts ...plugin.ExecOption,
) error

ScanImageIDs with a runtime and a list of IDs provided.

func ScanImages

func ScanImages(
	ctx context.Context, rang plugin.ExecRange,
	images []api.Image, opts ...plugin.ExecOption,
) error

ScanImages scans image provided by image list.

func ScanRuntime

func ScanRuntime(
	ctx context.Context, rang plugin.ExecRange,
	runtime api.Runtime, opts ...plugin.ExecOption,
) error

ScanRuntime scans a runtime provided.

func ScanRuntimes

func ScanRuntimes(
	ctx context.Context, rang plugin.ExecRange,
	runtimes []api.Runtime, opts ...plugin.ExecOption,
) error

ScanRuntimes scans runtime provided by runtime list.

func SetManifest

func SetManifest(m plugin.Manifest)

SetManifest specifies a manifest as default manifest.

The default manifest will only be used in the info command of the auto-generated entrypoint, when calling the Execute or ExecuteContext plugin.

Types

type ClusterHandler added in v1.3.0

type ClusterHandler func(*Command, api.Cluster) error

ClusterHandler is the handler for specified cluster.

type Command

type Command = cobra.Command

Command is libVeinMind plugin command that is built upon the widely used cobra framework.

func MapClusterCommand added in v1.3.0

func MapClusterCommand(
	c *Command, f ClusterHandler,
) *Command

MapClusterCommand issues defaultIndex.MapClusterCommand.

func MapContainerCommand added in v1.2.0

func MapContainerCommand(
	c *Command, f ContainerHandler,
) *Command

MapContainerCommand issues defaultIndex.MapContainerCommand.

func MapContainerIDsCommand added in v1.2.0

func MapContainerIDsCommand(
	c *Command, f ContainerIDsHandler,
) *Command

MapContainerIDsCommand issues defaultIndex.MapContainerIDsCommand.

func MapIACCommand added in v1.3.2

func MapIACCommand(c *Command, f IACHandler) *Command

func MapImageCommand

func MapImageCommand(
	c *Command, f ImageHandler,
) *Command

MapImageCommand issues defaultIndex.MapImageCommand.

func MapImageIDsCommand added in v1.1.0

func MapImageIDsCommand(
	c *Command, f ImageIDsHandler,
) *Command

MapImageIDsCommand issues defaultIndex.MapImageIDsCommand.

func MapModeCommand

func MapModeCommand(
	c *Command, typ string, obj interface{}, f ModeHandler,
) *Command

MapModeCommand issues defaultIndex.MapModeCommand.

func MapPluginCommand

func MapPluginCommand(
	c *Command, typ string, obj interface{}, f PluginHandler,
) *Command

MapPluginCommand issues defaultIndex.MapPluginCommand.

func MapRuntimeCommand

func MapRuntimeCommand(
	c *Command, f RuntimeHandler,
) *Command

MapRuntimeCommand issues defaultIndex.MapRuntimeCommand.

func NewInfoCommand

func NewInfoCommand(m plugin.Manifest) *Command

NewInfoCommand issues defaultIndex.NewInfoCommand.

type ContainerHandler added in v1.2.0

type ContainerHandler func(*Command, api.Container) error

ContainerHandler is the handler for specified containers.

type ContainerIDsHandler added in v1.2.0

type ContainerIDsHandler func(*Command, api.Runtime, []string) error

ContainerIDsHandler is the handler for current list of containers.

type IACHandler added in v1.3.2

type IACHandler func(*Command, iac.IAC) error

IACHandler is the handler for specified iac.

type ImageHandler

type ImageHandler func(*Command, api.Image) error

ImageHandler is the handler for specified images.

type ImageIDsHandler added in v1.1.0

type ImageIDsHandler func(*Command, api.Runtime, []string) error

ImageIDsHandler is the handler for current list of images.

type Index

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

Index for mapping user defined commands that is compatible with libVeinMind plugin system into command information.

func NewIndex

func NewIndex() *Index

NewIndex creates a new index object.

func (*Index) AddContainerCommand added in v1.2.0

func (idx *Index) AddContainerCommand(
	c *Command, f ContainerHandler,
)

AddContainerCommand invokes MapContainerCommand with no return.

func (*Index) AddContainerIDsCommand added in v1.2.0

func (idx *Index) AddContainerIDsCommand(
	c *Command, f ContainerIDsHandler,
)

AddContainerIDsCommand invokes MapContainerCommand with no return.

func (*Index) AddImageCommand

func (idx *Index) AddImageCommand(
	c *Command, f ImageHandler,
)

AddImageCommand invokes MapImageCommand with no return.

func (*Index) AddImageIDsCommand added in v1.1.0

func (idx *Index) AddImageIDsCommand(
	c *Command, f ImageIDsHandler,
)

AddImageIDsCommand invokes MapImageCommand with no return.

func (*Index) AddModeCommand

func (idx *Index) AddModeCommand(
	c *Command, typ string, obj interface{}, f ModeHandler,
)

AddModeCommand invokes MapModeCommand with no return.

func (*Index) AddPluginCommand

func (idx *Index) AddPluginCommand(
	c *Command, typ string, obj interface{}, f PluginHandler,
)

AddPluginCommand invokes MapPluginCommand with no return.

func (*Index) AddRuntimeCommand

func (idx *Index) AddRuntimeCommand(
	c *Command, f RuntimeHandler,
)

AddRuntimeCommand issues MapRuntimeCommand with no return.

func (*Index) MapClusterCommand added in v1.3.0

func (idx *Index) MapClusterCommand(
	c *Command, f ClusterHandler,
) *Command

MapClusterCommand attempts to create a cluster command.

The command will attempt to initialize the cluster object from specified mode with flags, and then invoke the function specified by caller.

func (*Index) MapContainerCommand added in v1.2.0

func (idx *Index) MapContainerCommand(
	c *Command, f ContainerHandler,
) *Command

MapContainerCommand attempts to create a container command.

The command will attempt to initialize the runtime object from specified mode with flags, scan and match containers in the runtime, and open matched containers, one at once.

func (*Index) MapContainerIDsCommand added in v1.2.0

func (idx *Index) MapContainerIDsCommand(
	c *Command, f ContainerIDsHandler,
) *Command

MapContainerIDsCommand attempts to create an container IDs command.

The command will attempt to initialize the runtime object from specified mode with flags, scan and match containers in the runtime, and collect those qualified container IDs.

func (*Index) MapIACCommand added in v1.3.2

func (idx *Index) MapIACCommand(
	c *Command, f IACHandler,
) *Command

MapIACCommand attempts to create a iac command.

func (*Index) MapImageCommand

func (idx *Index) MapImageCommand(
	c *Command, f ImageHandler,
) *Command

MapImageCommand attempts to create a image command.

The command will attempt to initialize the runtime object from specified mode with flags, scan and match images in the runtime, and open matched images, one at once.

func (*Index) MapImageIDsCommand added in v1.1.0

func (idx *Index) MapImageIDsCommand(
	c *Command, f ImageIDsHandler,
) *Command

MapImageIDsCommand attempts to create an image IDs command.

The command will attempt to initialize the runtime object from specified mode with flags, scan and match images in the runtime, and collect those qualified image IDs.

func (*Index) MapModeCommand

func (idx *Index) MapModeCommand(
	c *Command, typ string, obj interface{}, f ModeHandler,
) *Command

MapModeCommand attempts to create a mode command.

The command will lookup the specified mode, initialize root objects, then invoke the function provided by caller.

func (*Index) MapPluginCommand

func (idx *Index) MapPluginCommand(
	c *Command, typ string, obj interface{}, f PluginHandler,
) *Command

MapPluginCommand creates a plugin command node.

The function sets up and handle initialization of some plugin components so that the plugin command can work as is expected.

The provided command must have its Run and RunE function vacant when caling the function, otherwise the function raises a panic.

The obj specified will be marshaled into json and supplied to plugin.Command field. If it cannot be marshaled this function will also raises a panic.

The result is just the same as input command, but we will still return that for the package document to aggregate.

func (*Index) MapRuntimeCommand

func (idx *Index) MapRuntimeCommand(
	c *Command, f RuntimeHandler,
) *Command

MapRuntimeCommand attempts to create a runtime command.

The command will attempt to initialize the runtime object from specified mode with flags, and then invoke the function specified by caller.

func (*Index) NewInfoCommand

func (idx *Index) NewInfoCommand(m plugin.Manifest) *Command

NewInfoCommand creates an info command node.

type Mode

type Mode interface {
	Name() string
	AddFlags(*pflag.FlagSet)
	Invoke(*Command, []string, ModeHandler) error
}

Mode is a delegated object that initializes root object(s), manage their lifecycle(s) and pass it to subcommand.

Mode are arranged on the same level, being selected by "--mode" flag and detail specified through flags. But different modes might possesses completely different root object provision traits.

type ModeHandler

type ModeHandler func(*Command, []string, interface{}) error

ModeHandler is the handler for the selected mode.

type Partitioner

type Partitioner interface{}

Partitioner is the function that decompose concrete type into root object and arguments.

When the partitioner is for the root type itself, the form of "func(Type) Root" is just ok, and no argument will be generated this case. When the partitioner is for some object beneath the root, then "func(Type) (Root, string)" is required. The Type will be used for registering directly.

type PluginHandler

type PluginHandler func(*Command, []string) error

PluginHandler is the handler for valid plugin command.

type Root

type Root interface {
	Mode() string
	Options() plugin.ExecOption
}

Root is the search root for each commands.

When executing a plugin command, we will first specify mode and its related flags, which creates a search root for entities waiting to come, then specify the identifiers for entities (e.g. api.Image).

type RuntimeHandler

type RuntimeHandler func(*Command, api.Runtime) error

RuntimeHandler is the handler for specified runtimes.

type UniqueRoot

type UniqueRoot interface {
	Root
	ID() interface{}
}

UniqueRoot is a root which can be uniquely identified.

The identifier should be a hashable object and we will use sync.Map.Store to store that object as key.

Jump to

Keyboard shortcuts

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