output

package
v0.0.0-...-acbe8ed Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package output provides output formatting utilities for CLI commands.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedDataType = errors.New("unsupported data type for table output")

ErrUnsupportedDataType is returned when an unsupported data type is provided.

Functions

func FormatError

func FormatError(err error) map[string]interface{}

FormatError formats an error for JSON output.

func FormatSuccess

func FormatSuccess(message string, data interface{}) map[string]interface{}

FormatSuccess formats a success message for JSON output.

func NewTable

func NewTable(writer io.Writer) table.Writer

NewTable creates a new table writer with default styling.

func PrintError

func PrintError(writer io.Writer, message string)

PrintError prints an error message in red.

func PrintJSON

func PrintJSON(writer io.Writer, data interface{}) error

PrintJSON is a helper to print any data as JSON.

func PrintKeyValue

func PrintKeyValue(writer io.Writer, pairs map[string]string)

PrintKeyValue prints key-value pairs in a formatted way.

func PrintMessage

func PrintMessage(writer io.Writer, message string)

PrintMessage prints a plain message.

func PrintSuccess

func PrintSuccess(writer io.Writer, message string)

PrintSuccess prints a success message in green.

func PrintTable

func PrintTable(writer io.Writer, headers []string, rows [][]interface{})

PrintTable prints a table with headers and rows.

func PrintWarning

func PrintWarning(writer io.Writer, message string)

PrintWarning prints a warning message in yellow.

Types

type Format

type Format string

Format represents the output format for CLI commands.

const (
	// FormatText outputs human-readable tables and key-value pairs.
	FormatText Format = "text"
	// FormatJSON outputs pretty-printed JSON.
	FormatJSON Format = "json"
	// FormatJSONL outputs one JSON object per line (newline-delimited JSON).
	FormatJSONL Format = "jsonl"
)

type JSONLOutputter

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

JSONLOutputter outputs data as newline-delimited JSON (one object per line).

func NewJSONLOutputter

func NewJSONLOutputter(writer io.Writer) *JSONLOutputter

NewJSONLOutputter creates a new JSONL outputter.

func (*JSONLOutputter) Print

func (o *JSONLOutputter) Print(data interface{}) error

Print outputs data as a single JSON line.

func (*JSONLOutputter) PrintError

func (o *JSONLOutputter) PrintError(err error) error

PrintError outputs an error as a single JSON line.

func (*JSONLOutputter) Success

func (o *JSONLOutputter) Success(message string) error

Success prints a success message as a single JSON line.

type JSONOutputter

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

JSONOutputter outputs data in JSON format.

func NewJSONOutputter

func NewJSONOutputter(writer io.Writer) *JSONOutputter

NewJSONOutputter creates a new JSON outputter.

func (*JSONOutputter) Print

func (o *JSONOutputter) Print(data interface{}) error

Print outputs data as JSON.

func (*JSONOutputter) PrintError

func (o *JSONOutputter) PrintError(err error) error

PrintError outputs an error as JSON.

func (*JSONOutputter) Success

func (o *JSONOutputter) Success(message string) error

Success prints a success message as JSON.

type Outputter

type Outputter interface {
	// Print outputs data in the appropriate format
	Print(data interface{}) error
	// PrintError outputs an error message
	PrintError(err error) error
	// Success prints a success message
	Success(message string) error
}

Outputter defines the interface for different output formats.

func NewOutputter

func NewOutputter(format Format, writer io.Writer) Outputter

NewOutputter creates an outputter based on the format.

type TableOutputter

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

TableOutputter outputs data in human-readable table format.

func NewTableOutputter

func NewTableOutputter(writer io.Writer) *TableOutputter

NewTableOutputter creates a new table outputter.

func (*TableOutputter) Print

func (o *TableOutputter) Print(data interface{}) error

Print outputs data as a formatted table.

func (*TableOutputter) PrintError

func (o *TableOutputter) PrintError(err error) error

PrintError outputs an error message in red.

func (*TableOutputter) Success

func (o *TableOutputter) Success(message string) error

Success prints a success message in green.

Jump to

Keyboard shortcuts

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