Documentation
¶
Index ¶
- Variables
- func DiscoverFields(obj map[string]any) []string
- func Error(stdout io.Writer, message string, args ...any)
- func ExtractFields(obj map[string]any, fields []string) map[string]any
- func Info(stdout io.Writer, message string, args ...any)
- func Success(stdout io.Writer, message string, args ...any)
- func Warning(stdout io.Writer, message string, args ...any)
- type FieldSelectCodec
- type Options
- func (opts *Options) BindFlags(flags *pflag.FlagSet)
- func (opts *Options) Codec() (format.Codec, error)
- func (opts *Options) DefaultFormat(name string)
- func (opts *Options) Encode(dst io.Writer, value any) error
- func (opts *Options) RegisterCustomCodec(name string, codec format.Codec)
- func (opts *Options) Validate() error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DiscoverFields ¶
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 ExtractFields ¶
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).
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) Codec ¶
Codec returns the codec for the configured output format. We have to return an interface here.