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 ¶
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 ¶
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.