Documentation
¶
Index ¶
- func ApplyJQFilter(expr string, data any) (any, error)
- func ColorStatus(status string, isTTY bool, noColor bool) string
- func NewTable(w io.Writer, isTTY bool) table.Writer
- func TerminalWidth() int
- func TimeAgo(isoString string) string
- func TruncateString(s string, max int) string
- 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) PrintKeyValue(pairs [][2]string)
- 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 ColorStatus ¶ added in v0.4.0
ColorStatus wraps a status string with ANSI color codes for TTY display. Green: active, success. Red: error, failed. Yellow: paused, running, pending. Returns the unmodified string when not a TTY or when noColor is true.
func NewTable ¶
NewTable returns a table.Writer configured for the current output context. When isTTY is true, a go-pretty table with StyleLight (box-drawing) is returned. When false, a lightweight TSV writer is returned that outputs tab-separated values with no headers or borders, making `kh wf ls | cut -f2` work like gh.
func TerminalWidth ¶ added in v0.4.0
func TerminalWidth() int
TerminalWidth returns the width of the terminal connected to stdout. Returns 120 as a sensible default if the width cannot be determined.
func TimeAgo ¶ added in v0.4.0
TimeAgo converts an ISO 8601 timestamp string to a human-friendly relative time like "2h ago", "3d ago", or "just now". On parse error it returns the original string unchanged.
func TruncateString ¶ added in v0.4.0
TruncateString truncates s to max characters. If s exceeds max, it is shortened and "..." is appended. max must be at least 4 for truncation to apply; otherwise the original string is returned.
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) PrintKeyValue ¶ added in v0.4.0
PrintKeyValue prints key-value pairs in a left-aligned format. In TTY mode: keys are padded to the longest key width with a colon and tab. In non-TTY mode: same tab-separated format. Example:
ID: abc123 Name: My Workflow Status: active
func (*Printer) PrintTable ¶
PrintTable creates a go-pretty table, calls populateFn to add headers/rows, then renders.