output

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package output provides stable JSON envelope construction, JSON serialization, and human-readable table rendering for canvas-cli commands.

Index

Constants

View Source
const (
	CodeSuccess          = 0
	CodeGenericError     = 1
	CodeValidationError  = 2
	CodeAuthError        = 3
	CodePermissionDenied = 4
	CodeRateLimit        = 5
	CodeNetworkError     = 6
	CodeSafetyBlocked    = 7
	CodePartialFailure   = 8
)

Exit codes matching the taxonomy in docs/json-contract.md.

View Source
const SchemaVersion = canvas.SchemaVersion

SchemaVersion is re-exported from the canvas package for convenience.

Variables

This section is empty.

Functions

func ExitCodeForCategory added in v0.4.0

func ExitCodeForCategory(category string) int

ExitCodeForCategory maps a JSON error category to a process exit code. Unknown categories map to CodeGenericError.

func NewError

func NewError(err *canvas.ErrorInfo, command string, metaOverrides ...canvas.Meta) canvas.Envelope

NewError builds an error Envelope with ok=false. Every envelope carries a fresh request_id (uuid v4). Optional meta overrides are merged onto the base Meta.

func NewSuccess

func NewSuccess(data any, command string, metaOverrides ...canvas.Meta) canvas.Envelope

NewSuccess builds a success Envelope with ok=true and the given data. Every envelope carries a fresh request_id (uuid v4). Optional meta overrides are merged onto the base Meta.

func WriteJSON

func WriteJSON(w io.Writer, envelope *canvas.Envelope, pretty bool) error

WriteJSON serializes an Envelope to the writer as JSON. When pretty is true the output is indented; otherwise it is compact.

Types

type Table

type Table struct {
	Headers []string
	Rows    [][]string
}

Table holds column headers and row data for human-readable output.

func (Table) Render

func (t Table) Render(w io.Writer, noColor bool) error

Render writes a formatted ASCII table to w. Headers are bold when the output is a terminal and noColor is false; otherwise no ANSI escape codes are emitted.

Jump to

Keyboard shortcuts

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