output

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Truncate

func Truncate(s string, maxLen int) string

Truncate truncates a string to the given max length, adding "..." if truncated

func ValidateSkipHeader added in v1.4.0

func ValidateSkipHeader(skipHeader bool, format string) error

ValidateSkipHeader returns an error if --skip-header is used with a format that has no header row (e.g. JSON or YAML).

Types

type Column

type Column struct {
	Header string
	Width  int
	Value  func(item interface{}) string
}

Column represents a table column configuration

type Format

type Format string

Format represents the output format type

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatYAML  Format = "yaml"
	FormatWide  Format = "wide"
	FormatCSV   Format = "csv"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses a format string into a Format type

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter handles output formatting

func NewFormatter

func NewFormatter(format Format, w io.Writer, opts ...FormatterOption) *Formatter

NewFormatter creates a formatter for the specified output format

func (*Formatter) Format

func (f *Formatter) Format() Format

Format returns the configured format

func (*Formatter) Print

func (f *Formatter) Print(data interface{}) error

Print outputs data in the configured format (JSON or YAML only) For table format, use the type-specific table printing functions

func (*Formatter) PrintCSV added in v1.5.0

func (f *Formatter) PrintCSV(columns []Column, data []interface{}) error

PrintCSV prints data as CSV using the given columns. Header values are lowercased for consistency with query CSV output.

func (*Formatter) PrintJSON

func (f *Formatter) PrintJSON(data interface{}) error

PrintJSON outputs data as pretty-printed JSON

func (*Formatter) PrintTable

func (f *Formatter) PrintTable(columns []Column, data []interface{}) error

PrintTable prints a table with the given columns and data

func (*Formatter) PrintYAML

func (f *Formatter) PrintYAML(data interface{}) error

PrintYAML outputs data as YAML via JSON (sigs.k8s.io/yaml). This ensures json tags, omitempty, and custom MarshalJSON methods are respected.

type FormatterOption added in v1.4.0

type FormatterOption func(*Formatter)

FormatterOption configures optional Formatter behavior.

func WithSkipHeader added in v1.4.0

func WithSkipHeader(skip bool) FormatterOption

WithSkipHeader omits the header row from table output.

Jump to

Keyboard shortcuts

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