output

package
v0.3.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidFormat

func IsValidFormat(format string) bool

IsValidFormat checks if the given format string is valid

func ValidFormats

func ValidFormats() []string

ValidFormats returns all valid output formats

Types

type Format

type Format string

Format represents the output format type

const (
	// FormatTable outputs data as a formatted table (default)
	FormatTable Format = "table"
	// FormatJSON outputs data as JSON
	FormatJSON Format = "json"
	// FormatYAML outputs data as YAML
	FormatYAML Format = "yaml"
)

type Formatter

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

Formatter handles output formatting for CLI commands

func NewFormatter

func NewFormatter(format string) (*Formatter, error)

NewFormatter creates a new formatter with the specified format

func (*Formatter) Format

func (f *Formatter) Format() Format

Format returns the current format

func (*Formatter) NewTablePrinter

func (f *Formatter) NewTablePrinter() *TablePrinter

NewTablePrinter creates a new table printer

func (*Formatter) Print

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

Print outputs data in the configured format For table format, data should implement TableData interface For JSON/YAML, data is serialized directly

func (*Formatter) PrintJSON

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

PrintJSON outputs data as JSON

func (*Formatter) PrintTable

func (f *Formatter) PrintTable(data TableData) error

PrintTable outputs TableData as a formatted table

func (*Formatter) PrintYAML

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

PrintYAML outputs data as YAML

func (*Formatter) SetWriter

func (f *Formatter) SetWriter(w io.Writer)

SetWriter sets the output writer (useful for testing)

type TableData

type TableData interface {
	// Headers returns the column headers for the table
	Headers() []string
	// Rows returns the data rows for the table
	Rows() [][]string
}

TableData interface for types that can be rendered as tables

type TablePrinter

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

TablePrinter provides a fluent interface for building tables

func (*TablePrinter) Flush

func (t *TablePrinter) Flush() error

Flush writes the buffered output

func (*TablePrinter) Header

func (t *TablePrinter) Header(columns ...string) *TablePrinter

func (*TablePrinter) Row

func (t *TablePrinter) Row(values ...interface{}) *TablePrinter

Jump to

Keyboard shortcuts

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