Documentation
¶
Overview ¶
Package output renders API responses for the sectors CLI.
The CLI is agent-facing first: the default output is the API's raw JSON, emitted losslessly. When stdout is an interactive terminal we pretty-print for humans; when piped (the common case for an agent) we stay compact and machine-parseable. Errors are emitted as JSON on stderr with a non-zero exit code so callers can branch on them programmatically.
Index ¶
- func Category(status int) (category string, retryable bool)
- func Count(body []byte) ([]byte, error)
- func EmitError(status int, msg string, body []byte)
- func EmitJSON(w io.Writer, body []byte, format Format) error
- func IsTTY(f *os.File) bool
- func Project(body []byte, paths []string) ([]byte, error)
- func Truncate(body []byte, max int) ([]byte, error)
- type Format
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Category ¶
Category classifies an HTTP status into a stable, agent-friendly bucket and reports whether the condition is retryable. status 0 means a client-side or transport error.
func Count ¶
Count reduces a response to {"count": n}, where n is the length of the primary list (or 1 for a single object).
func EmitError ¶
EmitError writes a structured error to stderr as JSON. status is the HTTP status code when the error came from the API (0 for client-side errors), and body is the API's raw error payload if any. The envelope always carries a `category` and (when true) `retryable` so agents can branch programmatically.
func EmitJSON ¶
EmitJSON writes a raw JSON document (as returned by the API) to w in the requested format. body must already be valid JSON.
Types ¶
type Format ¶
type Format string
Format selects how successful responses are rendered.
const ( // FormatAuto picks Pretty on a TTY, JSON otherwise. FormatAuto Format = "auto" // FormatJSON is compact single-line JSON. FormatJSON Format = "json" // FormatPretty is indented JSON. FormatPretty Format = "pretty" // FormatTable renders tabular responses as a table, falling back to Pretty // for data that isn't a list of records. FormatTable Format = "table" )
func ParseFormat ¶
ParseFormat validates a --output value.