Documentation
¶
Overview ¶
Package output provides formatters for CLI output: text tables, JSON envelopes, jq filtering, and error rendering. All commands use this package to produce output.
Index ¶
- func ApplyJQ(w io.Writer, jsonData []byte, expr string) error
- func MarshalForJQ(data interface{}) ([]byte, error)
- func NewTable(w io.Writer) table.Writer
- func OutputError(w io.Writer, err error, asJSON bool)
- func RelativeTime(iso8601 string) string
- type Formatter
- func (f *Formatter) IsJSON() bool
- func (f *Formatter) OutputData(data interface{}, tableFn TableFunc) error
- func (f *Formatter) OutputDryRun(payload interface{}, validation string, tableFn TableFunc) error
- func (f *Formatter) OutputDryRunWithContext(extras map[string]interface{}, payload interface{}, validation string, ...) error
- func (f *Formatter) OutputList(items interface{}, pagination *PaginationMeta, tableFn TableFunc) error
- func (f *Formatter) OutputMutation(extras map[string]interface{}, tableFn TableFunc) error
- func (f *Formatter) RawJSON(data interface{}) error
- type PaginationMeta
- type TableFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyJQ ¶
ApplyJQ filters jsonData with a jq expression and writes raw text output to w. Matches gh CLI --jq behavior: strings are printed unquoted, other values as JSON.
func MarshalForJQ ¶
MarshalForJQ serializes data to JSON bytes, suitable for ApplyJQ input.
func NewTable ¶
NewTable creates a go-pretty table writer with a clean, borderless style suitable for CLI output. The table writes to w.
func OutputError ¶
OutputError renders err to w (typically stderr). When asJSON is true, outputs the CLIError JSON envelope. When asJSON is false, outputs human-readable text with suggestion.
func RelativeTime ¶
RelativeTime converts an ISO 8601 timestamp to a human-readable relative string such as "5 minutes ago" or "yesterday". If parsing fails, the raw input is returned unchanged (graceful degradation). Only used for table output — JSON always preserves the original ISO 8601 value.
Types ¶
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter handles output routing between JSON and text (table) modes. Commands call its methods instead of writing directly to stdout.
func NewFormatter ¶
NewFormatter creates a Formatter. asJSON enables JSON output, jqExpr applies a jq filter (implies JSON mode).
func (*Formatter) OutputData ¶
OutputData renders a single data object: bare JSON or text table.
func (*Formatter) OutputDryRun ¶
OutputDryRun renders a dry-run preview. JSON includes dry_run:true plus payload and validation. Text renders via the supplied table function.
func (*Formatter) OutputDryRunWithContext ¶
func (f *Formatter) OutputDryRunWithContext(extras map[string]interface{}, payload interface{}, validation string, tableFn TableFunc) error
OutputDryRunWithContext renders a dry-run preview with optional extra context fields merged at the JSON top level (e.g., key, comment_id). Text output is unaffected by extras.
func (*Formatter) OutputList ¶
func (f *Formatter) OutputList(items interface{}, pagination *PaginationMeta, tableFn TableFunc) error
OutputList renders a list with pagination: JSON envelope or text table.
func (*Formatter) OutputMutation ¶
OutputMutation renders a mutation result: {"ok":true, ...} or text.
type PaginationMeta ¶
type PaginationMeta = api.PaginationMeta
PaginationMeta describes the pagination state returned in list JSON envelopes. Re-exported from api package to avoid breaking callers.