Documentation
¶
Index ¶
- func ApplyJQFilter(expr string, data any) (any, error)
- func NewTable(w io.Writer, isTTY bool) table.Writer
- func WriteJSON(w io.Writer, data any) error
- func WriteJSONError(w io.Writer, message string, code int) error
- type Printer
- func (p *Printer) IsJSON() bool
- func (p *Printer) PrintData(data any, populateFn func(table.Writer)) error
- func (p *Printer) PrintDryRun(message string)
- func (p *Printer) PrintError(message string, code int) error
- func (p *Printer) PrintJSON(data any) error
- func (p *Printer) PrintTable(populateFn func(table.Writer))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyJQFilter ¶
ApplyJQFilter runs the given jq expression against data in-process (no external binary). If the expression produces exactly one result, it is returned directly. If it produces multiple results, they are returned as []any.
func NewTable ¶
NewTable returns a go-pretty table.Writer configured to write to w. When isTTY is true, table.StyleLight is used (box-drawing characters). When false, table.StyleDefault is used (ASCII, suitable for piped output).
Types ¶
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer routes command output to JSON, jq-filtered JSON, or human table based on the global --json and --jq flags.
func NewPrinter ¶
NewPrinter creates a Printer by reading --json and --jq flags from the cobra command. If --jq is set, JSON mode is implied.
func (*Printer) PrintData ¶
PrintData writes data to stdout. In JSON/jq mode it calls PrintJSON; otherwise it calls populateFn with a table.Writer. Pass nil for populateFn if only JSON output is needed.
func (*Printer) PrintDryRun ¶
PrintDryRun writes a dry-run message to stdout. In JSON mode it writes {"dry_run": true, "message": "..."}. In table mode it writes "[dry-run] message\n".
func (*Printer) PrintError ¶
PrintError writes an error message to stderr. In JSON mode it writes {"error": "...", "code": N}. In table mode it writes plain text.
func (*Printer) PrintJSON ¶
PrintJSON writes data as indented JSON to stdout. If a jq expression is configured, the filter is applied first.
func (*Printer) PrintTable ¶
PrintTable creates a go-pretty table, calls populateFn to add headers/rows, then renders.