output

package
v1.95.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GOutputTemplate string
)

Functions

func JSON

func JSON(o interface{})

JSON prints a JSON-formatted rendering of o to the terminal.

func Table

func Table(o interface{})

Table prints a table-formatted rendering of o to the terminal. If the object is of iterable type (slice only), each item is printed in a table row, with a header containing one column per type field. Otherwise, each field of the object is printed in a key/value formatted table, and a header is printed if the item type implements an optional (Type() string) method.

func TemplateAnnotations

func TemplateAnnotations(o interface{}) []string

TemplateAnnotations returns a list of annotations available for use with an output template.

func Text

func Text(o interface{})

Text prints a template-based plain text rendering of o to the terminal. If the object is of iterable type (slice only), each item is printed on a new line. If none is provided by the user, the default template prints all fields separated by a tabulation character.

Types

type Outputter

type Outputter interface {
	ToTable()
	ToJSON()
	ToText()
}

Outputter is an interface that must to be implemented by the commands output objects. In addition to the methods, types implementing this interface can also use struct tags to modify the output logic:

  • output:"-" is similar to package encoding/json, i.e. that a field with this tag will not be displayed
  • outputLabel:"..." overrides the string displayed as label, which by default is the field's CamelCase named split with spaces

type StreamingOutputter added in v1.95.0

type StreamingOutputter interface {
	Push(row any) error
	Close() error
}

StreamingOutputter is implemented by row-typed outputs that can be emitted progressively. Push is goroutine-safe; Close finalizes the render (flushes JSON, etc.).

func NewStreamer added in v1.95.0

func NewStreamer(rowType any, w io.Writer) StreamingOutputter

NewStreamer returns the right StreamingOutputter for the active globalstate.OutputFormat. rowType is a zero-value of the row struct used to derive table headers and the JSON envelope element type. w is where the streamer writes (typically os.Stdout).

Jump to

Keyboard shortcuts

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