Documentation
¶
Index ¶
- func FormatValue(v any) string
- type Format
- type Formatter
- func (f *Formatter) Format() string
- func (f *Formatter) Print(data any) error
- func (f *Formatter) PrintBytes(data []byte) error
- func (f *Formatter) PrintError(err error, code string, details map[string]any)
- func (f *Formatter) PrintRaw(data []byte) error
- func (f *Formatter) SetProjector(p Projector)
- func (f *Formatter) SetQuiet(q bool)
- func (f *Formatter) SetWriter(w io.Writer)
- func (f *Formatter) Writer() io.Writer
- type Projector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatValue ¶
FormatValue converts a value to its string representation for table/csv/plain output.
Types ¶
type Format ¶
type Format string
Format represents an output format
const ( FormatTable Format = "table" FormatJSON Format = "json" FormatJSONMulti Format = "json-multi" // internal: like json but triggers column selection in selectTableColumns FormatCSV Format = "csv" FormatYAML Format = "yaml" FormatPlain Format = "plain" FormatXML Format = "xml" // Classic API native format — pretty-printed XML FormatRaw Format = "raw" // Exact wire bytes, no conversion or formatting )
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter handles output formatting
func (*Formatter) PrintBytes ¶
PrintBytes writes bytes to the output. XML is pretty-printed unless the format is FormatRaw, which writes exact wire bytes. Used by Classic API commands to emit XML when no structured format is requested.
func (*Formatter) PrintError ¶
PrintError outputs an error in the appropriate format
func (*Formatter) PrintRaw ¶
PrintRaw outputs raw bytes (usually JSON from the API). XML responses (from Classic API) are converted to JSON before formatting, unless the format is FormatXML (pretty-printed) or FormatRaw (exact wire bytes).
func (*Formatter) SetProjector ¶ added in v1.17.0
SetProjector configures field-level projection (e.g. --compact) applied before format-specific rendering. A zero-value projector is a no-op.
func (*Formatter) SetQuiet ¶ added in v1.17.0
SetQuiet suppresses advisory output written to stderr (e.g. the list-size hint). Errors and primary output on stdout are unaffected.
type Projector ¶ added in v1.17.0
Projector applies field-level projection to flattened rows before format-specific rendering. Compact keeps only scalar fields after flattening, dropping arrays and nested remnants. Select keeps only the listed dot paths. When both are set, Select wins. The projector is shared by every output format (json, table, csv, yaml, plain) so projection behaves consistently.
func (Projector) Apply ¶ added in v1.17.0
Apply returns rows projected per the configured rules. Always flattens nested objects to dot keys so projection sees a flat shape. Empty rows pass through unchanged.
Select uses flattenRowsRaw (no common-prefix stripping) so user-supplied dot paths like "general.name" still match on single-section responses where stripCommonPrefix would otherwise rewrite "general.name" → "name" and silently produce empty projections.