printer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlignDefault = Align(tw.AlignDefault)
	AlignCenter  = Align(tw.AlignCenter)
	AlignRight   = Align(tw.AlignRight)
	AlignLeft    = Align(tw.AlignLeft)
)
View Source
const NonJSONIndent = "  "

Variables

This section is empty.

Functions

func RegisterEnumToStringConverter

func RegisterEnumToStringConverter[T ~int32](p *Printer, prefix string, resourceNameMap map[int32]string)

Types

type Align

type Align tw.Align

type Colorer

type Colorer func(string, ...any) string

type DiffOptions

type DiffOptions struct {
	// If true print all lines, otherwise only print changed lines
	Verbose bool
	// Disable color output
	NoColor bool
}

type PrintResourceOptions

type PrintResourceOptions struct {
	// Fields is a list of fields to print, if empty all fields are printed. This is ignored for JSON output.
	Fields []string
	// SpecFields is a list of fields to print from the "Spec" sub-object, if empty all fields are printed. This is ignored for JSON output.
	SpecFields []string
	// EmitDefaultValues prints fields holding their default value (e.g. 0, false, "") instead of omitting them.
	// Unset pointer fields (proto messages and presence-sensing scalars) remain omitted in both output modes.
	EmitDefaultValues bool
}

type PrintStructuredIter

type PrintStructuredIter interface {
	// Nil when done
	Next() (any, error)
}

type Printer

type Printer struct {
	// Must always be present
	Output io.Writer
	JSON   bool
	// Only used for JSON, defaults to no indent
	JSONIndent           string
	JSONPayloadShorthand bool
	// Only used for non-JSON, defaults to RFC3339
	FormatTime func(time.Time) string
	// Only used for non-JSON, defaults to color.Magenta
	TableHeaderColorer Colorer
	// contains filtered or unexported fields
}

func (*Printer) EndList

func (p *Printer) EndList()

Must be called after Printer.StartList or will panic. See Godoc on that function for more details.

func (*Printer) Print

func (p *Printer) Print(s ...string)

Ignored during JSON output

func (*Printer) PrintDiff

func (p *Printer) PrintDiff(a, b any, options DiffOptions) error

func (*Printer) PrintResource

func (p *Printer) PrintResource(resource any, options PrintResourceOptions) error

func (*Printer) PrintResourceList

func (p *Printer) PrintResourceList(
	resourceListResp any,
	options PrintResourceOptions,
	tableOptions TableOptions,
) error

func (*Printer) PrintResponseWithAsyncOperation

func (p *Printer) PrintResponseWithAsyncOperation(resource any, options PrintResourceOptions) error

func (*Printer) PrintStructured

func (p *Printer) PrintStructured(v any, options StructuredOptions) error

For JSON, if v is a proto message, protojson encoding is used

func (*Printer) PrintStructuredTableIter

func (p *Printer) PrintStructuredTableIter(
	typ reflect.Type,
	iter PrintStructuredIter,
	options StructuredOptions,
) error

Fields must be present for table

func (*Printer) Println

func (p *Printer) Println(s ...string)

Ignored during JSON output

func (*Printer) Printlnf

func (p *Printer) Printlnf(s string, v ...any)

Ignored during JSON output

func (*Printer) RegisterTextConverter

func (p *Printer) RegisterTextConverter(converter func(any) (string, bool))

func (*Printer) StartList

func (p *Printer) StartList()

When called for JSON with indent, this will create an initial bracket and make sure all Printer.PrintStructured calls get commas properly to appear as a list (but the indention and multiline posture of the JSON remains). When called for JSON without indent, this will make sure all Printer.PrintStructured is on its own line (i.e. JSONL mode). When called for non-JSON, this is a no-op.

Printer.EndList must be called at the end. If this is called twice it will panic. This and the end call are not safe for concurrent use.

type StructuredOptions

type StructuredOptions struct {
	// Derived if not present. Ignored for JSON printing.
	Fields []string
	// Ignored for JSON printing.
	ExcludeFields []string
	// If not set, not printed as table in text mode. This is ignored for JSON
	// printing.
	Table                        *TableOptions
	OverrideJSONPayloadShorthand *bool
	// Indent this many additional times when printing non-JSON
	NonJSONExtraIndent int
	// EmitDefaultValues when set to true, fields holding their default value (e.g. 0, false, "") are printed instead of omitted.
	// Unset pointer fields remain omitted.
	EmitDefaultValues bool
}

type TableOptions

type TableOptions struct {
	// If not set for a field, maximum width of all rows for structured, and no
	// width for streaming table. Field width will always at least be field name.
	FieldWidths map[string]int
	// Fields are align-left by default
	FieldAlign map[string]Align
	NoHeader   bool
}

Jump to

Keyboard shortcuts

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