Documentation
¶
Overview ¶
Package output provides output formatting utilities for CLI commands.
Index ¶
- Variables
- func FormatError(err error) map[string]interface{}
- func FormatSuccess(message string, data interface{}) map[string]interface{}
- func NewTable(writer io.Writer) table.Writer
- func PrintError(writer io.Writer, message string)
- func PrintJSON(writer io.Writer, data interface{}) error
- func PrintKeyValue(writer io.Writer, pairs map[string]string)
- func PrintMessage(writer io.Writer, message string)
- func PrintSuccess(writer io.Writer, message string)
- func PrintTable(writer io.Writer, headers []string, rows [][]interface{})
- func PrintWarning(writer io.Writer, message string)
- type Format
- type JSONLOutputter
- type JSONOutputter
- type Outputter
- type TableOutputter
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedDataType = errors.New("unsupported data type for table output")
ErrUnsupportedDataType is returned when an unsupported data type is provided.
Functions ¶
func FormatError ¶
FormatError formats an error for JSON output.
func FormatSuccess ¶
FormatSuccess formats a success message for JSON output.
func PrintError ¶
PrintError prints an error message in red.
func PrintKeyValue ¶
PrintKeyValue prints key-value pairs in a formatted way.
func PrintMessage ¶
PrintMessage prints a plain message.
func PrintSuccess ¶
PrintSuccess prints a success message in green.
func PrintTable ¶
PrintTable prints a table with headers and rows.
func PrintWarning ¶
PrintWarning prints a warning message in yellow.
Types ¶
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.
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.