package printers
import "k8s.io/cli-runtime/pkg/printers"
Package printers is helper for formatting and printing runtime objects into primitives io.writer.
Index ¶
- Variables
- func AllowsColorOutput(w io.Writer) bool
- func EscapeTerminal(in string) string
- func GetNewTabWriter(output io.Writer) *tabwriter.Writer
- func GetObjectGroupKind(obj runtime.Object) schema.GroupKind
- func IsInternalObjectError(err error) bool
- func IsTerminal(i interface{}) bool
- func WriteEscaped(writer io.Writer, output string) error
- type GoTemplatePrinter
- func NewGoTemplatePrinter(tmpl []byte) (*GoTemplatePrinter, error)
- func (p *GoTemplatePrinter) AllowMissingKeys(allow bool)
- func (p *GoTemplatePrinter) PrintObj(obj runtime.Object, w io.Writer) error
- type HumanReadablePrinter
- type JSONPathPrinter
- func NewJSONPathPrinter(tmpl string) (*JSONPathPrinter, error)
- func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error
- type JSONPrinter
- type NamePrinter
- type OmitManagedFieldsPrinter
- type PrintOptions
- type ResourcePrinter
- type ResourcePrinterFunc
- func NewDiscardingPrinter() ResourcePrinterFunc
- func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error
- type TypeSetterPrinter
- func NewTypeSetter(typer runtime.ObjectTyper) *TypeSetterPrinter
- func (p *TypeSetterPrinter) PrintObj(obj runtime.Object, w io.Writer) error
- func (p *TypeSetterPrinter) ToPrinter(delegate ResourcePrinter) ResourcePrinter
- func (p *TypeSetterPrinter) WrapToPrinter(delegate ResourcePrinter, err error) (ResourcePrinter, error)
- type WarningPrinter
- func NewWarningPrinter(out io.Writer, opts WarningPrinterOptions) *WarningPrinter
- func (w *WarningPrinter) Print(message string)
- type WarningPrinterOptions
- type YAMLPrinter
Variables ¶
var InternalObjectPreventer = &illegalPackageSourceChecker{disallowedPackagePrefixes}
var (
InternalObjectPrinterErr = "a versioned object must be passed to a printer"
)
Functions ¶
func AllowsColorOutput ¶
AllowsColorOutput returns true if the specified writer is a terminal and the process environment indicates color output is supported and desired.
func EscapeTerminal ¶
EscapeTerminal escapes terminal special characters in a human readable (but non-reversible) format.
func GetNewTabWriter ¶
GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text.
func GetObjectGroupKind ¶
func IsInternalObjectError ¶
func IsTerminal ¶
func IsTerminal(i interface{}) bool
IsTerminal returns whether the passed object is a terminal or not
func WriteEscaped ¶
WriteEscaped replaces unsafe terminal characters with replacement strings and writes them to the given writer.
Types ¶
type GoTemplatePrinter ¶
type GoTemplatePrinter struct {
// contains filtered or unexported fields
}
GoTemplatePrinter is an implementation of ResourcePrinter which formats data with a Go Template.
func NewGoTemplatePrinter ¶
func NewGoTemplatePrinter(tmpl []byte) (*GoTemplatePrinter, error)
func (*GoTemplatePrinter) AllowMissingKeys ¶
func (p *GoTemplatePrinter) AllowMissingKeys(allow bool)
AllowMissingKeys tells the template engine if missing keys are allowed.
func (*GoTemplatePrinter) PrintObj ¶
PrintObj formats the obj with the Go Template.
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 (*HumanReadablePrinter) PrintObj ¶
PrintObj prints the obj in a human-friendly format according to the type of the obj.
type JSONPathPrinter ¶
JSONPathPrinter is an implementation of ResourcePrinter which formats data with jsonpath expression.
func NewJSONPathPrinter ¶
func NewJSONPathPrinter(tmpl string) (*JSONPathPrinter, error)
func (*JSONPathPrinter) PrintObj ¶
PrintObj formats the obj with the JSONPath Template.
type JSONPrinter ¶
type JSONPrinter struct{}
JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
func (*JSONPrinter) PrintObj ¶
PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer.
type NamePrinter ¶
type NamePrinter struct { // ShortOutput indicates whether an operation should be // printed along side the "resource/name" pair for an object. ShortOutput bool // Operation describes the name of the action that // took place on an object, to be included in the // finalized "successful" message. Operation string }
NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
func (*NamePrinter) PrintObj ¶
PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object and print "resource/name" pair. If the object is a List, print all items in it.
type OmitManagedFieldsPrinter ¶
type OmitManagedFieldsPrinter struct { Delegate ResourcePrinter }
OmitManagedFieldsPrinter wraps an existing printer and omits the managed fields from the object before printing it.
func (*OmitManagedFieldsPrinter) PrintObj ¶
PrintObj copies the object and omits the managed fields from the copied object before printing it.
type PrintOptions ¶
type PrintOptions struct { NoHeaders bool WithNamespace bool WithKind bool Wide bool ShowLabels bool Kind schema.GroupKind ColumnLabels []string SortBy string // indicates if it is OK to ignore missing keys for rendering an output template. AllowMissingKeys bool }
PrintOptions struct defines a struct for various print options
type ResourcePrinter ¶
type ResourcePrinter interface { // PrintObj 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.
func NewTablePrinter ¶
func NewTablePrinter(options PrintOptions) ResourcePrinter
NewTablePrinter creates a printer suitable for calling PrintObj().
type ResourcePrinterFunc ¶
ResourcePrinterFunc is a function that can print objects
func NewDiscardingPrinter ¶
func NewDiscardingPrinter() ResourcePrinterFunc
NewDiscardingPrinter is a printer that discards all objects
func (ResourcePrinterFunc) PrintObj ¶
PrintObj implements ResourcePrinter
type TypeSetterPrinter ¶
type TypeSetterPrinter struct { Delegate ResourcePrinter Typer runtime.ObjectTyper }
TypeSetterPrinter is an implementation of ResourcePrinter wraps another printer with types set on the objects
func NewTypeSetter ¶
func NewTypeSetter(typer runtime.ObjectTyper) *TypeSetterPrinter
NewTypeSetter constructs a wrapping printer with required params
func (*TypeSetterPrinter) PrintObj ¶
PrintObj is an implementation of ResourcePrinter.PrintObj which sets type information on the obj for the duration of printing. It is NOT threadsafe.
func (*TypeSetterPrinter) ToPrinter ¶
func (p *TypeSetterPrinter) ToPrinter(delegate ResourcePrinter) ResourcePrinter
ToPrinter returns a printer (not threadsafe!) that has been wrapped
func (*TypeSetterPrinter) WrapToPrinter ¶
func (p *TypeSetterPrinter) WrapToPrinter(delegate ResourcePrinter, err error) (ResourcePrinter, error)
WrapToPrinter wraps the common ToPrinter method
type WarningPrinter ¶
type WarningPrinter struct {
// contains filtered or unexported fields
}
func NewWarningPrinter ¶
func NewWarningPrinter(out io.Writer, opts WarningPrinterOptions) *WarningPrinter
NewWarningPrinter returns an implementation of warningPrinter that outputs warnings to the specified writer.
func (*WarningPrinter) Print ¶
func (w *WarningPrinter) Print(message string)
Print prints warnings to the configured writer.
type WarningPrinterOptions ¶
type WarningPrinterOptions struct { // Color indicates that warning output can include ANSI color codes Color bool }
WarningPrinterOptions controls the behavior of a WarningPrinter constructed using NewWarningPrinter()
type YAMLPrinter ¶
type YAMLPrinter struct {
// contains filtered or unexported fields
}
YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML. The input object is assumed to be in the internal version of an API and is converted to the given version first. If PrintObj() is called multiple times, objects are separated with a '---' separator.
func (*YAMLPrinter) PrintObj ¶
PrintObj prints the data as YAML.
Source Files ¶
discard.go doc.go interface.go json.go jsonpath.go managedfields.go name.go sourcechecker.go tableprinter.go tabwriter.go template.go terminal.go typesetter.go warningprinter.go yaml.go
- Version
- v0.32.2 (latest)
- Published
- Feb 13, 2025
- Platform
- linux/amd64
- Imports
- 26 packages
- Last checked
- 2 months ago –
Tools for package owners.