output

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) PrintMultiDocYAML added in v1.7.0

func (f *Formatter) PrintMultiDocYAML(items []interface{}) error

PrintMultiDocYAML outputs each item as a separate YAML document separated by "---". This produces a YAML stream that can be fed back to `apply -f -`.

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.

type Progress added in v1.7.0

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

Progress displays a progress bar on stderr when the total exceeds the threshold and stderr is a terminal. The bar adapts to the terminal width.

Layout:

Fetching 47 dashboards        ################                         45%
|--- label (30 chars) ------->|--- bar (adapts to terminal) -------->|pct|

func NewProgress added in v1.7.0

func NewProgress(assetType string, total int) *Progress

NewProgress creates a progress indicator. It only activates when total exceeds the threshold and stderr is a TTY.

func (*Progress) Done added in v1.7.0

func (p *Progress) Done()

Done clears the progress line.

func (*Progress) Update added in v1.7.0

func (p *Progress) Update(current int)

Update prints the current progress. Call this after each item is fetched.

Jump to

Keyboard shortcuts

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