output

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Table = "table"
	JSON  = "json"
	YAML  = "yaml"
)

Variables

This section is empty.

Functions

func ResourceColumns

func ResourceColumns() map[string][]string

ResourceColumns returns a copy of the declared per-resource column lists, for tests that check every declared column exists in the spec.

func Sanitize

func Sanitize(text string) string

Sanitize makes API-controlled text safe to print to a terminal.

A customer name is whatever the caller sent Lago, and a table cell prints it raw. QA created a customer whose name held an ANSI colour sequence and a newline: the escape recoloured the terminal and the newline injected a fake row. Every C0 and C1 control character (ESC, CR, LF, TAB, NUL, DEL, 0x80-0x9f) is therefore replaced by its visible escape, `\x1b`, `\n`, `\r`, `\t`, `\xNN`, and an invalid UTF-8 byte by `\xNN`. Replacing rather than stripping keeps the evidence: an operator sees that the name contains an escape instead of a silently shortened string. Printable text, including non-ASCII, is untouched. --output json is unaffected; encoding/json escapes on its own.

func WritePairs

func WritePairs(out io.Writer, pairs []Pair) error

WritePairs prints pairs in the order given, as the table renderer prints a resource: upper-case key, two-space gap, sanitised value. Blank values are skipped. Built-in commands whose output is a short identity block (`whoami`) use it so the order is the one a reader expects rather than alphabetical.

Types

type Pair

type Pair struct {
	Key   string
	Value string
}

Pair is one labelled value in a hand-ordered key/value table.

type Renderer

type Renderer struct {
	Mode  string
	Query string
	Out   io.Writer

	// Err receives diagnostics that must not pollute stdout: the hint printed when a
	// query matches nothing, and the paging hint under a partial list. Leaving it nil
	// discards them.
	Err io.Writer

	// Identifiers restricts default table output to the terse identifier block.
	// It applies to table output only: --output json and --output yaml always
	// carry the complete resource. See DECISIONS.md.
	Identifiers bool

	// AllPages is set by --all, which renders every page itself, so the per-page
	// "page N of M" hint would only be noise.
	AllPages bool
}

func (Renderer) Render

func (r Renderer) Render(value any) error

Jump to

Keyboard shortcuts

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