output

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 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 command results and errors in the formats the CLI supports: machine-readable JSON, and a pretty rendering that falls back to JSON when a value has no pretty printer.

stdout carries data only. Errors go to stderr, as text or as one compact JSON line, and never carry a secret.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, f Format, v any) error

Render writes v to w in the given format. JSON is indented with two spaces and ends with a newline. Pretty uses PrettyPrint when v implements Pretty and falls back to indented JSON otherwise.

func WriteError

func WriteError(w io.Writer, f ErrorFormat, err error)

WriteError writes err to w in the given format. JSON is one compact line ending in a newline. Text is "repsol: <message>" followed by "hint: <hint>" when the error has one. A nil error writes nothing.

Types

type Envelope

type Envelope struct {
	// Code is the snake_case machine code of the failure.
	Code string `json:"code"`
	// Category is the snake_case category name.
	Category string `json:"category"`
	// ExitCode is the process exit code of the failure.
	ExitCode int `json:"exit_code"`
	// Retryable reports whether repeating the call could succeed.
	Retryable bool `json:"retryable"`
	// Message is the human-readable description.
	Message string `json:"message"`
	// HTTPStatus is the status of the failing response, or 0.
	HTTPStatus int `json:"http_status"`
	// Endpoint is the API path of the failing call, or empty.
	Endpoint string `json:"endpoint"`
	// Hint tells the user what to do next, or is empty.
	Hint string `json:"hint"`
}

Envelope is the machine-readable form of a failure. Every key is always present, so consumers can rely on the shape. The values never contain a secret.

func EnvelopeFor

func EnvelopeFor(err error) Envelope

EnvelopeFor converts an error into its envelope. A nil error yields the zero envelope.

type ErrorFormat

type ErrorFormat string

ErrorFormat is the rendering format of errors on stderr.

const (
	// ErrorText is the default: one "repsol: ..." line and an optional hint.
	ErrorText ErrorFormat = "text"
	// ErrorJSON is one compact JSON envelope line.
	ErrorJSON ErrorFormat = "json"
)

The supported error formats.

func ResolveErrorFormat

func ResolveErrorFormat(flag, env string) (ErrorFormat, error)

ResolveErrorFormat picks the error format: the flag wins over the REPSOL_ERROR_FORMAT environment value, which wins over text.

type Format

type Format string

Format is the rendering format of command output.

const (
	// FormatJSON is indented JSON with snake_case keys.
	FormatJSON Format = "json"
	// FormatPretty is the human-readable rendering of a value.
	FormatPretty Format = "pretty"
)

The supported output formats.

func ResolveFormat

func ResolveFormat(flag string, stdoutTTY bool) (Format, error)

ResolveFormat picks the output format: an explicit flag wins, and an empty flag means pretty on a terminal and JSON otherwise.

type Pretty

type Pretty interface {
	// PrettyPrint writes the human-readable form of the value.
	PrettyPrint(w io.Writer) error
}

Pretty is implemented by values that have a human-readable rendering.

Jump to

Keyboard shortcuts

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