printers

package
v0.0.0-...-8b7d7e7 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Label

func Label(label string) string

Format label (extracted so that color could be added more easily to all labels)

func NewTabWriter

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

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

func ValidateRowPrintHandlerFunc

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.

func NewTableGenerator

func NewTableGenerator() *HumanReadablePrinter

NewTableGenerator creates a HumanReadablePrinter suitable for calling GenerateTable().

func NewTablePrinter

func NewTablePrinter(options PrintOptions) *HumanReadablePrinter

NewTablePrinter creates a printer suitable for calling PrintObj().

func (*HumanReadablePrinter) GenerateTable

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

GenerateTable 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) 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) TableHandler

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.

type PrefixWriter

type PrefixWriter interface {
	// Write writes text with the specified indentation level.
	Writef(format string, a ...interface{})
	// WriteLine writes an entire line with no indentation level.
	WriteLine(a ...interface{})
	// Write columns with an initial indentation
	WriteCols(cols ...string) PrefixWriter
	// Write columns with an initial indentation and a newline at the end
	WriteColsLn(cols ...string) PrefixWriter
	// Flush forces indentation to be reset.
	Flush() error
	// WriteAttribute writes the attr (as a label) with the given value and returns
	// a PrefixWriter for writing any subattributes.
	WriteAttribute(attr, value string) PrefixWriter
}

PrefixWriter can write text at various indentation levels.

func NewBarePrefixWriter

func NewBarePrefixWriter(out io.Writer) PrefixWriter

func NewPrefixWriter

func NewPrefixWriter(out io.Writer) PrefixWriter

NewPrefixWriter creates a new PrefixWriter.

type PrintHandler

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

type PrintOptions

type PrintOptions struct {
	NoHeaders bool
	//TODO: Add options for eg: with-kind, server-printing, wide etc
	AllNamespaces bool
}

PrintOptions for different table printing options

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 TableGenerator

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

Jump to

Keyboard shortcuts

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