output

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitOK           = 0  // Success
	ExitGeneral      = 1  // General error
	ExitUsage        = 2  // Invalid usage / bad arguments
	ExitAuth         = 3  // Authentication failure
	ExitNotFound     = 4  // Resource not found
	ExitConflict     = 5  // Conflict (resource already exists)
	ExitForbidden    = 6  // Permission denied
	ExitRateLimit    = 75 // Rate limited (EX_TEMPFAIL from sysexits.h)
	ExitTimeout      = 8  // Request timeout
	ExitAPIError     = 9  // Zoho API error (non-specific)
	ExitConfigError  = 10 // Configuration error
	ExitNetworkError = 11 // Network connectivity error
)

Exit codes following sysexits.h convention

Variables

This section is empty.

Functions

func ExitWithError

func ExitWithError(formatter Formatter, err error)

ExitWithError prints the error via the formatter and exits with the correct code

func PadString

func PadString(s string, width int) string

PadString pads a string to the specified width

func RenderTable

func RenderTable(w io.Writer, columns []Column, rows []map[string]string)

RenderTable renders a table to the writer for rich mode

func TruncateString

func TruncateString(s string, maxLen int) string

TruncateString truncates a string to maxLen and adds "..." if needed

Types

type CLIError

type CLIError struct {
	ExitCode int
	Message  string
	Hint     string
}

CLIError represents a structured error with exit code and optional hint

func NewCLIError

func NewCLIError(code int, msg string) *CLIError

NewCLIError creates a new CLIError

func (*CLIError) Error

func (e *CLIError) Error() string

Error implements the error interface

func (*CLIError) WithHint

func (e *CLIError) WithHint(hint string) *CLIError

WithHint adds a user-facing hint to the error

type Column

type Column struct {
	Name  string // Display name
	Key   string // Struct field name or map key
	Width int    // Width for rich mode (0 = auto)
}

Column defines a column for table/list output

type Formatter

type Formatter interface {
	Print(data any) error
	PrintList(items any, columns []Column) error
	PrintError(err error)
	PrintHint(msg string)
}

Formatter is the interface for output formatting

func New

func New(mode string) Formatter

New creates a formatter for the specified mode

func NewJSON

func NewJSON(resultsOnly bool) Formatter

NewJSON creates a JSON formatter with optional results-only mode

Jump to

Keyboard shortcuts

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