output

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(f Formatter, data interface{}, w io.Writer) error

Print outputs the formatted data to the writer

func PrintError

func PrintError(f Formatter, err error)

PrintError outputs the formatted error to stderr

Types

type ErrorDetail

type ErrorDetail struct {
	Code      string `json:"code,omitempty"`
	Message   string `json:"message"`
	Details   string `json:"details,omitempty"`
	Timestamp string `json:"timestamp"`
}

ErrorDetail contains error details

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents a JSON error response

type FormatType

type FormatType string

FormatType represents the output format type

const (
	FormatJSON  FormatType = "json"
	FormatTable FormatType = "table"
	FormatPlain FormatType = "plain"
)

type Formatter

type Formatter interface {
	// Format converts data to the appropriate output format
	Format(data interface{}) (string, error)

	// FormatError formats an error for output
	FormatError(err error) string
}

Formatter defines the interface for output formatting

func NewFormatter

func NewFormatter(opts Options) Formatter

NewFormatter creates a formatter based on options

type JSONFormatter

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

JSONFormatter formats output as JSON

func NewJSONFormatter

func NewJSONFormatter(opts Options) *JSONFormatter

NewJSONFormatter creates a new JSON formatter

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(data interface{}) (string, error)

Format converts data to JSON format

func (*JSONFormatter) FormatError

func (f *JSONFormatter) FormatError(err error) string

FormatError formats an error as JSON

type Options

type Options struct {
	Format  FormatType
	NoColor bool
	Quiet   bool
	Verbose bool
	Writer  io.Writer
}

Options holds formatting options

type PlainFormatter

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

PlainFormatter formats output as plain pipe-delimited text

func NewPlainFormatter

func NewPlainFormatter(opts Options) *PlainFormatter

NewPlainFormatter creates a new plain text formatter

func (*PlainFormatter) Format

func (f *PlainFormatter) Format(data interface{}) (string, error)

Format converts data to plain text format

func (*PlainFormatter) FormatError

func (f *PlainFormatter) FormatError(err error) string

FormatError formats an error as plain text

type SimpleTable

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

SimpleTable is a helper struct for simple tabular data

func NewSimpleTable

func NewSimpleTable(headers []string) *SimpleTable

NewSimpleTable creates a new simple table

func (*SimpleTable) AddRow

func (t *SimpleTable) AddRow(row ...string)

AddRow adds a row to the table

func (*SimpleTable) Headers

func (t *SimpleTable) Headers() []string

Headers returns the table headers

func (*SimpleTable) Rows

func (t *SimpleTable) Rows() [][]string

Rows returns all table rows

type TableData

type TableData interface {
	Headers() []string
	Rows() [][]string
}

TableData defines the interface for data that can be rendered as a table

type TableFormatter

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

TableFormatter formats output as a styled table

func NewTableFormatter

func NewTableFormatter(opts Options) *TableFormatter

NewTableFormatter creates a new table formatter

func (*TableFormatter) Format

func (f *TableFormatter) Format(data interface{}) (string, error)

Format converts data to a styled table format

func (*TableFormatter) FormatError

func (f *TableFormatter) FormatError(err error) string

FormatError formats an error for table output

Jump to

Keyboard shortcuts

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