commander

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrinterAllowedFormats is the configuration key for
	PrinterAllowedFormats = "allowedFormats"
	// PrinterOutputFormat is the configuration key for setting the initial output format
	PrinterOutputFormat = "outputFormat"
	// PrinterColumns is the configuration key for setting the initial column list
	PrinterColumns = "columns"
	// PrinterNoHeader is the configuration key for setting the initial suppress header flag
	PrinterNoHeader = "noHeader"
	// PrinterShowLabels is the configuration key for setting the initial show labels flag
	PrinterShowLabels = "showLabels"
	// PrinterHideStatus is the configuration key for setting the initial hide status flag
	PrinterHideStatus = "hideStatus"
)

Variables

View Source
var OnlyVersion runtime.GroupVersioner = onlyVersion{}

OnlyVersion is a group version that only resolves if there is a single possible kind

Functions

func AddPreRunE added in v1.5.0

func AddPreRunE(cmd *cobra.Command, preRunE func(*cobra.Command, []string) error)

AddPreRunE adds an error returning pre-run function to the supplied command, existing pre-run actions will run AFTER the supplied function, and only if the supplied pre-run function does not return an error

func ConfigGlobals

func ConfigGlobals(cfg *internalconfig.RedSkyConfig, cmd *cobra.Command)

ConfigGlobals sets up persistent globals for the supplied configuration

func MapErrors added in v1.7.1

func MapErrors(cmd *cobra.Command, f func(error) error)

MapErrors wraps all of the error returning functions on the supplied command (and it's sub-commands) so that they pass any errors through the mapping function.

func SetExperimentsAPI

func SetExperimentsAPI(api *experimentsv1alpha1.API, cfg redskyapi.Config, cmd *cobra.Command) error

SetExperimentsAPI creates a new experiments API interface from the supplied configuration

func SetKubePrinter added in v1.5.0

func SetKubePrinter(printer *ResourcePrinter, cmd *cobra.Command, additionalFormats map[string]AdditionalFormat)

SetKubePrinter assigns a client-go enabled resource printer during the pre-run of the supplied command

func SetPrinter added in v1.5.0

func SetPrinter(meta TableMeta, printer *ResourcePrinter, cmd *cobra.Command, additionalFormats map[string]AdditionalFormat)

SetPrinter assigns the resource printer during the pre-run of the supplied command

func SetStreams

func SetStreams(streams *IOStreams, cmd *cobra.Command)

SetStreams updates the streams using the supplied command

func StreamsPreRun

func StreamsPreRun(streams *IOStreams) func(cmd *cobra.Command, args []string)

StreamsPreRun is intended to be used as a pre-run function for commands when no other action is required

func WithContextE

func WithContextE(runE func(context.Context) error) func(*cobra.Command, []string) error

WithContextE wraps a function that accepts a context in one that accepts a command and argument slice

func WithoutArgsE

func WithoutArgsE(runE func() error) func(*cobra.Command, []string) error

WithoutArgsE wraps a no-argument function in one that accepts a command and argument slice

Types

type AdditionalFormat added in v1.6.4

type AdditionalFormat interface {
	NewPrinter(columns []string, noHeader, showLabels bool) (ResourcePrinter, error)
}

AdditionalFormat is a factory function for registering new formats

type ContextServer added in v1.5.0

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

ContextServer is a server bound to a context lifecycle

func NewContextServer added in v1.5.0

func NewContextServer(ctx context.Context, handler http.Handler, options ...ContextServerOption) *ContextServer

NewContextServer creates a new context server bound to the lifecycle of the supplied context

func (*ContextServer) ListenAndServe added in v1.5.0

func (cs *ContextServer) ListenAndServe() error

ListenAndServe will start the server and block, the resulting error may be from start up, start up handlers, or shutdown

type ContextServerOption added in v1.5.0

type ContextServerOption func(*ContextServer)

ContextServerOption is an option that can be applied to a context server

func HandleStart added in v1.5.0

func HandleStart(startUp func(string) error) ContextServerOption

HandleStart runs the supplied function with the server URL once the server is listening

func ShutdownOnIdle added in v1.5.0

func ShutdownOnIdle(idle time.Duration, onIdle func()) ContextServerOption

ShutdownOnIdle shuts the server down when all connections have been idle for a specified duration

func ShutdownOnInterrupt added in v1.5.0

func ShutdownOnInterrupt(onInterrupt func()) ContextServerOption

ShutdownOnInterrupt shuts the server down in response to a SIGINT or SIGTERM

func WithServerOptions added in v1.5.0

func WithServerOptions(serverOptions func(*http.Server)) ContextServerOption

WithServerOptions exposes the underlying HTTP server for configuration

type IOStreams

type IOStreams struct {
	// In is used to access the standard input stream (or it's override)
	In io.Reader
	// Out is used to access the standard output stream (or it's override)
	Out io.Writer
	// ErrOut is used to access the standard error output stream (or it's override)
	ErrOut io.Writer
}

IOStreams allows individual commands access to standard process streams (or their overrides).

func (*IOStreams) OpenFile added in v1.7.0

func (s *IOStreams) OpenFile(filename string) (io.ReadCloser, error)

OpenFile returns a read closer for the specified filename. If the filename is logically empty (i.e. "-"), the input stream is returned.

type NoPrinterError added in v1.5.0

type NoPrinterError struct {
	// OutputFormat is the requested output format
	OutputFormat string
	// AllowedFormats are the available output formats
	AllowedFormats []string
}

NoPrinterError is an error occurring when no suitable printer is available

func (NoPrinterError) Error added in v1.5.0

func (e NoPrinterError) Error() string

Error returns a useful message for a "no printer" error

type ResourcePrinter added in v1.5.0

type ResourcePrinter interface {
	// PrintObj formats the specified object to the specified writer
	PrintObj(interface{}, io.Writer) error
}

ResourcePrinter formats an object to a byte stream

type ResourcePrinterFunc added in v1.6.4

type ResourcePrinterFunc func(interface{}, io.Writer) error

ResourcePrinterFunc allows a simple function to be used as resource printer

func (ResourcePrinterFunc) NewPrinter added in v1.6.4

func (rpf ResourcePrinterFunc) NewPrinter([]string, bool, bool) (ResourcePrinter, error)

func (ResourcePrinterFunc) PrintObj added in v1.6.4

func (rpf ResourcePrinterFunc) PrintObj(obj interface{}, w io.Writer) error

type ResourceReader added in v1.7.0

type ResourceReader struct {
	Scheme           *runtime.Scheme
	PreferredVersion runtime.GroupVersioner
}

ResourceReader helps properly decode Kubernetes resources on the CLI. It is meant to be a lighter weight alternative to the cli-runtime resource.Builder.

func NewResourceReader added in v1.7.0

func NewResourceReader() *ResourceReader

NewResourceReader returns a new resource reader for the supplied byte stream.

func (*ResourceReader) ReadInto added in v1.7.0

func (r *ResourceReader) ReadInto(reader io.ReadCloser, target runtime.Object) error

ReadInto decodes the supplied byte stream into the target runtime object. The default values and type information of the target object will be populated.

type TableMeta added in v1.5.0

type TableMeta interface {
	// ExtractList accepts a single object (which possibly represents a list) and returns a slice to iterate over; this
	// should include a single element slice from the input object if it does not represent a list
	ExtractList(obj interface{}) ([]interface{}, error)
	// Columns returns the default list of columns to render for a given object (in some cases this may be overridden by the user)
	Columns(obj interface{}, outputFormat string, showLabels bool) []string
	// ExtractValue returns the column string value for a given object from the extract list result
	ExtractValue(obj interface{}, column string) (string, error)
	// Header returns the header value to use for a column
	Header(outputFormat string, column string) string
}

TableMeta is used to inspect objects for formatting

Jump to

Keyboard shortcuts

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