output

package
v3.0.0-rc49 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 RenderFunc

type RenderFunc func() string

RenderFunc is the protype of human format renderer functions.

type Renderer

type Renderer struct {
	DefaultOutput string
	Output        string

	// DefaultSort is the order a listing comes in when the caller asks
	// for none, as a comma separated list of the fields to order on, each
	// optionally prefixed with "-" to reverse it. Sort overrides it, and
	// a Sort beginning with "+" extends it, the way Output and
	// DefaultOutput already work. Without either, a listing is ordered
	// on its columns, left to right.
	DefaultSort string
	Sort        string

	Color         string
	Data          any
	HumanRenderer RenderFunc
	Colorize      *palette.ColorPaletteFunc
	Stream        bool
}

Renderer hosts the renderer options and data, and exposes the rendering method.

func (Renderer) Print

func (t Renderer) Print() error

Print prints the representation of the data in one of the supported format (json, flat, human, ...).

The human format needs a RenderFunc to be passed. Print writes the rendered data to stdout, and returns what stopped it from rendering.

The error is returned rather than written to stderr, so that a command whose output could not be rendered fails instead of succeeding silently. A misspelled column or sort field used to print a line to stderr and exit 0, which a script reading the empty stdout had no way to notice.

func (Renderer) Sprint

func (t Renderer) Sprint() (string, error)

Sprint returns the string representation of the data in one of the supported format (json, flat, human, ...).

The human format needs a RenderFunc to be passed.

type T

type T int

T encodes as an integer one of the supported output formats (json, flat, human, table, csv)

const (
	// Human is the preferred human friendly custom output format
	Human T = iota
	// JSON is the json output format
	JSON
	// Flat is the flattened json output format (a."b#b".c = d, a[0] = b)
	Flat
	// JSONLine is unindented json output format
	JSONLine
	// Tab is the customizable tabular output format
	Tab
	// Table is the simple tabular output format
	Table
	// CSV is the csv tabular output format
	CSV
	// YAML is the standard human readable, commentable, complex data representation
	YAML
	// Template is a custom user provided renderer
	Template
)

func New

func New(s string) T

New returns the integer value of the output format

func (T) MarshalText

func (t T) MarshalText() ([]byte, error)

MarshalText marshals the enum as a quoted json string

func (T) String

func (t T) String() string

func (*T) UnmarshalText

func (t *T) UnmarshalText(b []byte) error

UnmarshalText unmashals a quoted json string to the enum value

Jump to

Keyboard shortcuts

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