outfmt

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLimit

func GetLimit(ctx context.Context) int

GetLimit retrieves limit from context

func GetQuery

func GetQuery(ctx context.Context) string

GetQuery retrieves JQ query from context

func GetYes

func GetYes(ctx context.Context) bool

GetYes retrieves yes flag from context

func IsJSON

func IsJSON(ctx context.Context) bool

IsJSON checks if context has JSON-ish output format (json or jsonl).

func IsJSONL added in v1.4.1

func IsJSONL(ctx context.Context) bool

IsJSONL checks if context has JSONL output format.

func NewContext

func NewContext(ctx context.Context, format Format) context.Context

NewContext creates a context with output format

func Output

func Output(ctx context.Context, data any, textFormatter func()) error

Output writes data in the appropriate format (legacy, use Formatter.Output instead)

func Print

func Print(format string, args ...any)

Print outputs a simple message

func Println

func Println(args ...any)

Println outputs a line

func WithColorMode

func WithColorMode(ctx context.Context, mode ColorMode) context.Context

WithColorMode adds color mode to context

func WithFormat

func WithFormat(ctx context.Context, format string) context.Context

WithFormat adds output format to context (string-based for CLI flags)

func WithLimit

func WithLimit(ctx context.Context, limit int) context.Context

WithLimit adds limit to context

func WithQuery

func WithQuery(ctx context.Context, query string) context.Context

WithQuery adds JQ query to context

func WithYes

func WithYes(ctx context.Context, yes bool) context.Context

WithYes adds yes flag to context (for skipping confirmations)

func WriteJSON

func WriteJSON(data any, query string) error

WriteJSON outputs JSON, optionally filtered by JQ query

func WriteJSONTo

func WriteJSONTo(w io.Writer, data any, query string) error

WriteJSONTo outputs JSON to a writer, optionally filtered by JQ query.

Types

type ColorMode

type ColorMode string

ColorMode controls colored output.

const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

func GetColorMode

func GetColorMode(ctx context.Context) ColorMode

GetColorMode retrieves color mode from context

func ParseColorMode

func ParseColorMode(value string) ColorMode

ParseColorMode parses a color mode string.

type ColumnType

type ColumnType int

ColumnType defines how a column should be formatted

const (
	ColumnPlain ColumnType = iota
	ColumnStatus
	ColumnAmount
	ColumnCurrency
	ColumnDate
	ColumnID
)

type Format

type Format int

Format represents output format type

const (
	Text Format = iota
	JSON
	JSONL
)

func GetFormat

func GetFormat(ctx context.Context) Format

GetFormat retrieves format from context

func ParseFormat

func ParseFormat(value string) Format

ParseFormat parses an output format string.

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter provides tabular text output

func FromContext

func FromContext(ctx context.Context, opts ...OutputOption) *Formatter

FromContext creates a Formatter from context with optional options

func NewFormatter

func NewFormatter() *Formatter

NewFormatter creates a new text formatter (legacy, use FromContext instead)

func (*Formatter) Empty

func (f *Formatter) Empty(msg string)

Empty prints an empty result message

func (*Formatter) Flush

func (f *Formatter) Flush()

Flush writes all buffered output

func (*Formatter) Header

func (f *Formatter) Header(cols ...string)

Header writes a header row

func (*Formatter) Output

func (f *Formatter) Output(data any) error

Output writes data in the appropriate format (JSON or pretty-print)

func (*Formatter) Row

func (f *Formatter) Row(cols ...any)

Row writes a data row

func (*Formatter) Table

func (f *Formatter) Table(headers []string, rows [][]string, colTypes []ColumnType) error

Table outputs data in tabular format with optional column colorization

type OutputOption

type OutputOption func(*Formatter)

OutputOption configures the Formatter

func WithWriter

func WithWriter(w io.Writer) OutputOption

WithWriter sets a custom writer for output

Jump to

Keyboard shortcuts

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