output

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyJQFilter

func ApplyJQFilter(expr string, data any) (any, error)

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

func ColorStatus(status string, isTTY bool, noColor bool) string

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

func NewTable(w io.Writer, isTTY bool) table.Writer

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

func TimeAgo(isoString string) string

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

func TruncateString(s string, max int) string

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.

func WriteJSON

func WriteJSON(w io.Writer, data any) error

WriteJSON marshals data as indented JSON and writes it to w with a trailing newline.

func WriteJSONError

func WriteJSONError(w io.Writer, message string, code int) error

WriteJSONError writes {"error": message, "code": code} as indented JSON to w.

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

func NewPrinter(ios *iostreams.IOStreams, cmd *cobra.Command) *Printer

NewPrinter creates a Printer by reading --json and --jq flags from the cobra command. If --jq is set, JSON mode is implied.

func (*Printer) IsJSON

func (p *Printer) IsJSON() bool

IsJSON reports whether the printer is in JSON output mode.

func (*Printer) PrintData

func (p *Printer) PrintData(data any, populateFn func(table.Writer)) error

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

func (p *Printer) PrintDryRun(message string)

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

func (p *Printer) PrintError(message string, code int) error

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

func (p *Printer) PrintJSON(data any) error

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

func (p *Printer) PrintKeyValue(pairs [][2]string)

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

func (p *Printer) PrintTable(populateFn func(table.Writer))

PrintTable creates a go-pretty table, calls populateFn to add headers/rows, then renders.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL