output

package
v0.2.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Green  = color.New(color.FgGreen).SprintfFunc()
	Blue   = color.New(color.FgBlue).SprintfFunc()
	Red    = color.New(color.FgRed).SprintfFunc()
	Yellow = color.New(color.FgYellow).SprintfFunc()

	Bold = color.New(color.Bold).SprintfFunc()
)

Functions

func DiscoverFields

func DiscoverFields(obj map[string]any) []string

DiscoverFields enumerates the available field paths from a sample object map. It returns top-level keys and one level of spec.* sub-keys, sorted.

func Error

func Error(stdout io.Writer, message string, args ...any)

func ExtractFields

func ExtractFields(obj map[string]any, fields []string) map[string]any

ExtractFields is the exported equivalent of extractFields, for use by callers that need to apply field selection outside of Encode (e.g. partial failure envelopes).

func Info

func Info(stdout io.Writer, message string, args ...any)

func Success

func Success(stdout io.Writer, message string, args ...any)

func Warning

func Warning(stdout io.Writer, message string, args ...any)

Types

type FieldSelectCodec

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

FieldSelectCodec wraps the JSON codec and emits only the requested fields from each output object. It implements format.Codec.

Field paths support dot-notation (e.g. "metadata.name") which is resolved by walking nested maps.

For a single object the output is a flat JSON object containing only the selected fields. For a collection (printItems or unstructured.UnstructuredList) the output is {"items": [...]}.

Missing fields produce a null value rather than being omitted (FR-008).

func NewFieldSelectCodec

func NewFieldSelectCodec(fields []string) *FieldSelectCodec

NewFieldSelectCodec creates a FieldSelectCodec for the given field paths.

func (*FieldSelectCodec) Decode

func (c *FieldSelectCodec) Decode(src goio.Reader, value any) error

func (*FieldSelectCodec) Encode

func (c *FieldSelectCodec) Encode(dst goio.Writer, value any) error

Encode writes the selected fields to dst as JSON.

func (*FieldSelectCodec) Fields

func (c *FieldSelectCodec) Fields() []string

Fields returns the list of field paths this codec selects.

func (*FieldSelectCodec) Format

func (c *FieldSelectCodec) Format() format.Format

type Options

type Options struct {
	OutputFormat  string
	JSONFields    []string
	JSONDiscovery bool

	// IsPiped reports whether stdout is not connected to a terminal.
	// Populated from terminal.IsPiped() during BindFlags.
	IsPiped bool

	// NoTruncate reports whether table column truncation should be suppressed.
	// Populated from terminal.NoTruncate() during BindFlags.
	NoTruncate bool

	// ErrWriter is the writer for hints and diagnostics (defaults to os.Stderr).
	ErrWriter io.Writer
	// contains filtered or unexported fields
}

func (*Options) BindFlags

func (opts *Options) BindFlags(flags *pflag.FlagSet)

func (*Options) Codec

func (opts *Options) Codec() (format.Codec, error)

Codec returns the codec for the configured output format. We have to return an interface here.

func (*Options) DefaultFormat

func (opts *Options) DefaultFormat(name string)

func (*Options) Encode

func (opts *Options) Encode(dst io.Writer, value any) error

func (*Options) RegisterCustomCodec

func (opts *Options) RegisterCustomCodec(name string, codec format.Codec)

func (*Options) Validate

func (opts *Options) Validate() error

Jump to

Keyboard shortcuts

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