Help us shape the future of Go! Take the 2026 Go Developer Survey

output

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output renders command results as human-readable text or JSON. Commands build explicit DTOs for their output — never genqlient-generated structs — so the --json contract stays stable across schema regenerations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dash added in v0.6.0

func Dash(s *string) string

Dash renders an optional string cell: the value, or an em-dash placeholder when the pointer is nil or empty. Keeps "no value" columns consistent across the table-rendering commands.

func Write

func Write(s *IOStreams, asJSON bool, v any, table func(w io.Writer) error) error

Write renders v as indented JSON when asJSON is set, otherwise calls table to render the human view.

func WriteJSON

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

WriteJSON marshals v as indented JSON followed by a newline.

Types

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
	// contains filtered or unexported fields
}

IOStreams bundles the CLI's input/output handles so commands never touch os.Stdin/Stdout directly, keeping them testable.

func System

func System() *IOStreams

System returns IOStreams wired to the real process streams.

func Test

func Test() (*IOStreams, *bytes.Buffer, *bytes.Buffer)

Test returns IOStreams backed by buffers, plus the stdout and stderr buffers for assertions.

func (*IOStreams) IsInputTerminal

func (s *IOStreams) IsInputTerminal() bool

IsInputTerminal reports whether stdin is a TTY (i.e. a prompt can actually be answered).

func (*IOStreams) IsTerminal

func (s *IOStreams) IsTerminal() bool

IsTerminal reports whether stdout is a TTY.

type Table

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

Table is a thin tabwriter wrapper for aligned columnar output.

func NewTable

func NewTable(w io.Writer, headers ...string) *Table

func (*Table) Flush

func (t *Table) Flush() error

func (*Table) Row

func (t *Table) Row(cells ...string)

Jump to

Keyboard shortcuts

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