output

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package output provides a small result writer shared by all tg commands.

Commands produce a typed result and hand it to a Printer. In JSON mode the result is wrapped in a stable envelope ({"schema":N,"data":...}) so agents can parse it; in text mode a human-friendly rendering is used. All machine output goes to stdout; logs and progress must go to stderr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Formats

func Formats() []string

Formats lists the valid output formats (for completion and validation).

Types

type Format

type Format string

Format is the output format selected by the global --output flag.

const (
	Text Format = "text"
	JSON Format = "json"
)

Supported formats.

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat validates and returns the format for s.

type Printer

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

Printer writes command results in the configured format.

func New

func New(format Format, w io.Writer) *Printer

New returns a Printer writing to w in the given format.

func (*Printer) Emit

func (p *Printer) Emit(v any) error

Emit writes a single result value.

func (*Printer) Format

func (p *Printer) Format() Format

Format reports the printer's format.

func (*Printer) SetAccount

func (p *Printer) SetAccount(label string)

SetAccount sets the account label included with each emitted result. Empty disables it (single-account mode).

type TextMarshaler

type TextMarshaler interface {
	MarshalText(w io.Writer) error
}

TextMarshaler is implemented by results that render a custom text form. Results without it fall back to fmt's default formatting in text mode.

Jump to

Keyboard shortcuts

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