output

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package output renders a decoded API answer as JSON, YAML or a table.

Index

Constants

This section is empty.

Variables

Formats lists the accepted values of --output, in help order.

Functions

func Generic

func Generic(doc any) (any, error)

Generic turns any value into the map/slice/scalar shape the renderers work on. A json.RawMessage is decoded rather than re-encoded.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is an interactive terminal.

func Table

func Table(w io.Writer, value any) error

Table renders a decoded answer as an aligned table: a collection as one row per item, an object as a name/value list, a scalar as itself.

Types

type Format

type Format string

Format is one of the shapes an answer is printed in.

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

The supported formats.

func Default

func Default(w io.Writer) Format

Default is the format used when --output was not given: a table on an interactive terminal, JSON when the answer is being piped somewhere.

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat validates a --output value.

type Printer

type Printer struct {
	Out    io.Writer
	Format Format
}

Printer writes answers in one format.

func (Printer) Print

func (p Printer) Print(doc any) error

Print renders doc. Anything that is not already generic JSON is passed through encoding/json first, so a typed SDK view and a raw answer are rendered by exactly the same code.

Jump to

Keyboard shortcuts

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