format

package
v1.197.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCSVDelimiter = ","
	DefaultTSVDelimiter = "\t"
	ValueKey            = "value"
)
View Source
const (
	MaxColumnWidth     = 60 // Maximum width for a column.
	TableColumnPadding = 3  // Padding for table columns.
	DefaultKeyWidth    = 15 // Default base width for keys.
	KeyValue           = "value"
)

Constants for table formatting.

Variables

View Source
var (
	ErrTableTooWide = errors.New("the table is too wide to display properly")
)

Error variables for table formatting.

Functions

func CreateStyledTable added in v1.176.0

func CreateStyledTable(header []string, rows [][]string) string

createStyledTable creates a styled table with headers and rows.

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat checks if the provided format is valid.

Types

type DefaultFormatter

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

DefaultFormatter provides a base implementation of Formatter.

type DelimitedFormatter

type DelimitedFormatter struct {
	DefaultFormatter
	// contains filtered or unexported fields
}

DelimitedFormatter handles CSV and TSV format output.

func (*DelimitedFormatter) Format

func (f *DelimitedFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for DelimitedFormatter.

type Format

type Format string

Format represents the output format type.

const (
	FormatTable    Format = "table"
	FormatJSON     Format = "json"
	FormatYAML     Format = "yaml"
	FormatCSV      Format = "csv"
	FormatTSV      Format = "tsv"
	FormatTemplate Format = "template"
)

type FormatOptions

type FormatOptions struct {
	MaxColumns    int
	Delimiter     string
	TTY           bool
	Format        Format
	CustomHeaders []string
}

FormatOptions contains options for formatting output.

type Formatter

type Formatter interface {
	Format(data map[string]interface{}, options FormatOptions) (string, error)
}

Formatter defines the interface for formatting output.

func NewFormatter

func NewFormatter(format Format) (Formatter, error)

NewFormatter creates a new formatter for the specified format.

type JSONFormatter

type JSONFormatter struct {
	DefaultFormatter
}

JSONFormatter handles JSON format output.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for JSONFormatter.

type TableFormatter

type TableFormatter struct {
	DefaultFormatter
}

TableFormatter handles table format output.

func (*TableFormatter) Format

func (f *TableFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for TableFormatter.

type YAMLFormatter

type YAMLFormatter struct {
	DefaultFormatter
}

YAMLFormatter handles YAML format output.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(data map[string]interface{}, options FormatOptions) (string, error)

Format implements the Formatter interface for YAMLFormatter.

Jump to

Keyboard shortcuts

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