printer

package
v0.0.0-...-b394286 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseOutputToTemplateTypeAndElement

func ParseOutputToTemplateTypeAndElement(output string) (string, string)

ParseOutputToTemplateTypeAndElement parses the output into templateType and templateElement e.g. kcp runtimes -o custom="INSTANCE ID:instanceID,SHOOTNAME:shootName" After parsing, the templateType = "custom" and templateElement = "INSTANCE ID:instanceID,SHOOTNAME:shootName"

func RelaxedJSONPathExpression

func RelaxedJSONPathExpression(pathExpression string) (string, error)

RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:

  • metadata.name (no leading '.' or curly braces '{...}'
  • {metadata.name} (no leading '.')
  • .metadata.name (no curly braces '{...}')
  • {.metadata.name} (complete expression)

And transforms them all into a valid jsonpath expression:

{.metadata.name}

Types

type Column

type Column struct {
	Header string
	// FieldSpec is a JSONPath expression which specifies the field(s) to be printed
	FieldSpec string
	// FieldFormatter is a formatter fuction to print complex columns derived from object field(s).
	FieldFormatter FieldFormatterFunc
	// contains filtered or unexported fields
}

Column represents a user specified column. If FieldFormatter is not nil, it takes precedence over FieldSpec

func ParseColumnToHeaderAndFieldSpec

func ParseColumnToHeaderAndFieldSpec(spec string) ([]Column, error)

ParseColumnToHeaderAndFieldSpec parses a custom columns contents to a list of Column <header>:<jsonpath-field-spec> pairs. e.g. spec is INSTANCE ID:instanceID,SHOOTNAME:shootName columnsOut[0].Header = "INSTANCE ID" and columnsOut[0].FieldSpec = "{.instanceID}" columnsOut[1].Header = "SHOOTNAME" and columnsOut[1].FieldSpec = "{.shootName}"

type FieldFormatterFunc

type FieldFormatterFunc func(obj interface{}) string

FieldFormatterFunc is a function type to format and return the string representation of an object field.

type JSONPrinter

type JSONPrinter interface {
	PrintObj(obj interface{}) error
}

JSONPrinter prints objects in JSON format

func NewJSONPrinter

func NewJSONPrinter(indent string) JSONPrinter

NewJSONPrinter creates a new JSONPrinter. If indent is set to a non-empty string, the output will be pretty-printed, and the specified string will be applied for each level of indentation.

type TablePrinter

type TablePrinter interface {
	PrintObj(obj interface{}) error
	SetRuntimeEvents(eventList []events.EventDTO, lvl string)
}

TablePrinter prints objects in table format, according to the given column definitions.

func NewTablePrinter

func NewTablePrinter(columns []Column, noHeaders bool) (TablePrinter, error)

NewTablePrinter creates a new TablePrinter. The parameter columns holds the non-empty list of Column specifications which comprises the table. If the parameter noHeaders is true, the first header row will not be displayed.

Jump to

Keyboard shortcuts

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