printers

package
v1.14.10 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAllLabels added in v1.7.0

func AppendAllLabels(showLabels bool, itemLabels map[string]string) string

Append all labels to a single column. We need this even when show-labels flag* is false, since this adds newline delimiter to the end of each row.

func AppendLabels added in v1.7.0

func AppendLabels(itemLabels map[string]string, columnLabels []string) string

func DecorateTable added in v1.7.0

func DecorateTable(table *metav1beta1.Table, options PrintOptions) error

DecorateTable takes a table and attempts to add label columns and the namespace column. It will fill empty columns with nil (if the object does not expose metadata). It returns an error if the table cannot be decorated.

func FormatResourceName added in v1.7.0

func FormatResourceName(kind schema.GroupKind, name string, withKind bool) string

FormatResourceName receives a resource kind, name, and boolean specifying whether or not to update the current name to "kind/name"

func GetNewTabWriter

func GetNewTabWriter(output io.Writer) *tabwriter.Writer

GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text.

func PrintTable added in v1.7.0

func PrintTable(table *metav1beta1.Table, output io.Writer, options PrintOptions) error

PrintTable prints a table to the provided output respecting the filtering rules for options for wide columns and filtered rows. It filters out rows that are Completed. You should call DecorateTable if you receive a table from a remote server before calling PrintTable.

func ValidatePrintHandlerFunc added in v1.7.0

func ValidatePrintHandlerFunc(printFunc reflect.Value) error

ValidatePrintHandlerFunc validates print handler signature. printFunc is the function that will be called to print an object. It must be of the following type:

func printFunc(object ObjectType, w io.Writer, options PrintOptions) error

where ObjectType is the type of the object that will be printed. DEPRECATED: will be replaced with ValidateRowPrintHandlerFunc

func ValidateRowPrintHandlerFunc added in v1.7.0

func ValidateRowPrintHandlerFunc(printFunc reflect.Value) error

ValidateRowPrintHandlerFunc validates print handler signature. printFunc is the function that will be called to print an object. It must be of the following type:

func printFunc(object ObjectType, options PrintOptions) ([]metav1beta1.TableRow, error)

where ObjectType is the type of the object that will be printed, and the first return value is an array of rows, with each row containing a number of cells that match the number of columns defined for that printer function.

Types

type HumanReadablePrinter

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

HumanReadablePrinter is an implementation of ResourcePrinter which attempts to provide more elegant output. It is not threadsafe, but you may call PrintObj repeatedly; headers will only be printed if the object type changes. This makes it useful for printing items received from watches.

func NewHumanReadablePrinter

func NewHumanReadablePrinter(decoder runtime.Decoder, options PrintOptions) *HumanReadablePrinter

NewHumanReadablePrinter creates a HumanReadablePrinter. If encoder and decoder are provided, an attempt to convert unstructured types to internal types is made.

func NewTablePrinter added in v1.7.0

func NewTablePrinter() *HumanReadablePrinter

NewTablePrinter creates a HumanReadablePrinter suitable for calling PrintTable().

func (*HumanReadablePrinter) AddTabWriter added in v1.7.0

func (a *HumanReadablePrinter) AddTabWriter(t bool) *HumanReadablePrinter

AddTabWriter sets whether the PrintObj function will format with tabwriter (true by default).

func (*HumanReadablePrinter) DefaultTableHandler added in v1.8.0

func (h *HumanReadablePrinter) DefaultTableHandler(columnDefinitions []metav1beta1.TableColumnDefinition, printFunc interface{}) error

DefaultTableHandler registers a set of columns and a print func that is given a chance to process any object without an explicit handler. Only the most recently set print handler is used. See ValidateRowPrintHandlerFunc for required method signature.

func (*HumanReadablePrinter) EnsurePrintHeaders

func (h *HumanReadablePrinter) EnsurePrintHeaders()

EnsurePrintHeaders sets the HumanReadablePrinter option "NoHeaders" to false and removes the .lastType that was printed, which forces headers to be printed in cases where multiple lists of the same resource are printed consecutively, but are separated by non-printer related information.

func (*HumanReadablePrinter) HandledResources

func (h *HumanReadablePrinter) HandledResources() []string

func (*HumanReadablePrinter) Handler

func (h *HumanReadablePrinter) Handler(columns, columnsWithWide []string, printFunc interface{}) error

Handler adds a print handler with a given set of columns to HumanReadablePrinter instance. See ValidatePrintHandlerFunc for required method signature.

func (*HumanReadablePrinter) PrintObj

func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) error

PrintObj prints the obj in a human-friendly format according to the type of the obj.

func (*HumanReadablePrinter) PrintTable added in v1.7.0

func (h *HumanReadablePrinter) PrintTable(obj runtime.Object, options PrintOptions) (*metav1beta1.Table, error)

PrintTable returns a table for the provided object, using the printer registered for that type. It returns a table that includes all of the information requested by options, but will not remove rows or columns. The caller is responsible for applying rules related to filtering rows or columns.

func (*HumanReadablePrinter) TableHandler added in v1.7.0

func (h *HumanReadablePrinter) TableHandler(columnDefinitions []metav1beta1.TableColumnDefinition, printFunc interface{}) error

TableHandler adds a print handler with a given set of columns to HumanReadablePrinter instance. See ValidateRowPrintHandlerFunc for required method signature.

func (*HumanReadablePrinter) With added in v1.7.0

type PrintHandler added in v1.7.0

type PrintHandler interface {
	Handler(columns, columnsWithWide []string, printFunc interface{}) error
	TableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error
	DefaultTableHandler(columns []metav1beta1.TableColumnDefinition, printFunc interface{}) error
}

type PrintOptions

type PrintOptions struct {
	// supported Format types can be found in pkg/printers/printers.go
	OutputFormatType     string
	OutputFormatArgument string

	NoHeaders          bool
	WithNamespace      bool
	WithKind           bool
	Wide               bool
	ShowLabels         bool
	AbsoluteTimestamps bool
	Kind               schema.GroupKind
	ColumnLabels       []string

	SortBy string

	// indicates if it is OK to ignore missing keys for rendering an output template.
	AllowMissingKeys bool
}

type ResourcePrinter

type ResourcePrinter interface {
	// Print receives a runtime object, formats it and prints it to a writer.
	PrintObj(runtime.Object, io.Writer) error
}

ResourcePrinter is an interface that knows how to print runtime objects.

type ResourcePrinterFunc

type ResourcePrinterFunc func(runtime.Object, io.Writer) error

ResourcePrinterFunc is a function that can print objects

func (ResourcePrinterFunc) PrintObj

func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error

PrintObj implements ResourcePrinter

type TablePrinter added in v1.7.0

type TablePrinter interface {
	PrintTable(obj runtime.Object, options PrintOptions) (*metav1beta1.Table, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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