output

package
v0.1.5 Latest Latest
Warning

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

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

Documentation

Overview

Package output contains output contracts and exit code helpers.

Index

Constants

View Source
const (
	// ExitOK indicates successful command execution.
	ExitOK = 0
	// ExitGeneric indicates an unclassified command failure.
	ExitGeneric = 1
	// ExitUsage indicates invalid CLI usage.
	ExitUsage = 2
	// ExitAuth indicates authentication or authorization failures.
	ExitAuth = 10
	// ExitValidation indicates invalid input or semantic validation errors.
	ExitValidation = 11
	// ExitNotFound indicates that the requested resource does not exist.
	ExitNotFound = 12
	// ExitNetwork indicates transport-level failures such as timeouts or DNS/connectivity issues.
	ExitNetwork = 13
	// ExitServer indicates server-side failures.
	ExitServer = 14
)

Variables

This section is empty.

Functions

func AuthError

func AuthError(message string) error

AuthError wraps an authentication/authorization failure.

func Code

func Code(err error) int

Code maps an error to a process exit code.

func FromHTTPStatus

func FromHTTPStatus(status int) int

FromHTTPStatus maps an HTTP status code to a stable CLI exit code.

func NetworkError

func NetworkError(message string) error

NetworkError wraps a transport failure.

func NotFoundError

func NotFoundError(message string) error

NotFoundError wraps a missing-resource failure.

func ServerError

func ServerError(message string) error

ServerError wraps a server-side failure.

func UsageError

func UsageError(message string) error

UsageError wraps a usage error with the standard exit code.

func ValidationError

func ValidationError(message string) error

ValidationError wraps a client input validation failure.

Types

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError carries a stable process exit code together with an error.

func (ExitError) Error

func (e ExitError) Error() string

Error returns the wrapped error text when available.

func (ExitError) Unwrap

func (e ExitError) Unwrap() error

Unwrap exposes the wrapped error.

type Format

type Format string

Format selects output rendering mode.

const (
	FormatHuman Format = "human"
	FormatJSON  Format = "json"
	FormatTable Format = "table"
	FormatQuiet Format = "quiet"
)

func ParseFormat

func ParseFormat(raw string) (Format, error)

ParseFormat validates and parses output format.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer is a small abstraction for stable stdout rendering.

func NewRenderer

func NewRenderer(out io.Writer, format Format) *Renderer

NewRenderer creates a new renderer.

func (*Renderer) PrintTable

func (r *Renderer) PrintTable(headers []string, rows [][]string) error

PrintTable prints tabular data in human/table mode.

func (*Renderer) PrintValue

func (r *Renderer) PrintValue(value interface{}) error

PrintValue prints a generic value according to the selected format.

Jump to

Keyboard shortcuts

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