output

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the version of the JSON envelope below. Consumers — CI pipelines, the planned editor extension — parse this, so it is versioned from the first release that emits it rather than after the first breaking change.

Bump it only for a breaking change to an envelope's `data` shape, and record what changed in docs/json-output.md.

Variables

This section is empty.

Functions

func Print

func Print(format Format, data any, headers []string, toRows func(data any) [][]string) error

Print dispatches to JSON or Table output based on format. For table output, the caller must provide headers and a toRow function.

func PrintEnvelope added in v2.1.0

func PrintEnvelope(w io.Writer, kind string, data any) error

PrintEnvelope writes a versioned envelope. kind names the payload shape, e.g. "diff".

func PrintJSON

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

PrintJSON writes data as indented JSON to w.

func PrintTable

func PrintTable(w io.Writer, headers []string, rows [][]string)

PrintTable writes tabular data. headers are column names, rows is a slice of row slices.

Types

type Envelope added in v2.1.0

type Envelope struct {
	SchemaVersion int    `json:"schemaVersion"`
	Kind          string `json:"kind"`
	Data          any    `json:"data"`
}

Envelope wraps machine-readable output in a self-describing, versioned structure.

Commands that predate this print their payload bare. New commands whose output is a contract — anything CI or an editor consumes — use the envelope, so a consumer can tell which shape it is reading instead of guessing.

type Format

type Format string

Format represents the output format.

const (
	FormatJSON  Format = "json"
	FormatTable Format = "table"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat validates and returns a Format.

Jump to

Keyboard shortcuts

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