output

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package output renders results and errors as text or JSON and defines exit codes.

Index

Constants

View Source
const (
	ExitOK         = 0
	ExitUnexpected = 1
	ExitUsage      = 2
	ExitAuth       = 3
	ExitConflict   = 4
	ExitNotFound   = 5
	ExitForbidden  = 6
	ExitNetwork    = 7
)

Variables

This section is empty.

Functions

func Quote added in v0.3.0

func Quote(s string) string

Quote returns s as is, or Go-quoted when it has an unsafe rune: text that often comes from the server (an error cause, a name) then stays on one line and shows what it carries.

func UnsafeRune added in v0.3.0

func UnsafeRune(r rune) bool

UnsafeRune is a rune that can break or disguise a line of text output: controls, line and paragraph separators, and format characters such as bidi overrides.

func WriteError

func WriteError(w io.Writer, m Mode, e *Error) error

WriteError renders the error envelope.

func WriteFields

func WriteFields(w io.Writer, fields []Field) error

WriteFields prints aligned "key: value" lines for text mode.

func WriteJSON

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

WriteJSON writes v as indented JSON without HTML escaping.

Types

type Error

type Error struct {
	Code     string `json:"code"`
	Source   string `json:"source,omitempty"`
	Stage    string `json:"stage,omitempty"`
	Cause    string `json:"cause,omitempty"`
	Recovery string `json:"recovery,omitempty"`
	Exit     int    `json:"-"`
}

Error is the stable error envelope. Cause must never contain secrets.

func AsError

func AsError(err error) *Error

AsError returns err as *Error, wrapping unknown errors as "unexpected".

func (*Error) Error

func (e *Error) Error() string

type Field

type Field struct{ Key, Value string }

type Mode

type Mode int
const (
	Text Mode = iota
	JSON
)

func DetectMode

func DetectMode(flag string, isTTY bool) (Mode, error)

DetectMode picks the output mode: explicit flag wins, otherwise text on a TTY and JSON elsewhere.

Jump to

Keyboard shortcuts

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