format

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package format provides formatters for command output.

Package format provides common output formatting utilities for CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(data any, globalFlags *globals.Flags) error

Any handles the common pattern of formatting any data type for output. This is useful for commands with custom data structures.

func Authors

func Authors(authors []*catalogs.Author, globalFlags *globals.Flags) error

Authors handles the common pattern of formatting authors for output.

func Models

func Models(models []*catalogs.Model, showDetails bool, globalFlags *globals.Flags) error

Models handles the common pattern of formatting models for output. This encapsulates the switch logic for different output formats.

func Providers

func Providers(providers []*catalogs.Provider, checker *auth.Checker, supportedMap map[string]bool, globalFlags *globals.Flags) error

Providers handles the common pattern of formatting providers for output.

Types

type Data

type Data struct {
	Headers         []string
	Rows            [][]string
	ColumnAlignment []table.Align // Optional: column alignment (use table.AlignDefault, table.AlignLeft, table.AlignCenter, table.AlignRight)
}

Data represents data formatted for table output.

type Format

type Format string

Format types for output.

const (
	// FormatTable represents table output format.
	FormatTable Format = "table"
	// FormatJSON represents JSON output format.
	FormatJSON Format = "json"
	// FormatYAML represents YAML output format.
	FormatYAML Format = "yaml"
	// FormatWide represents wide table output format.
	FormatWide Format = "wide"
)

func DetectFormat

func DetectFormat(explicitFormat string) Format

DetectFormat auto-detects format based on terminal and environment.

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat converts string to Format with validation.

type Formatter

type Formatter interface {
	Format(w io.Writer, data any) error
}

Formatter interface for all output types.

func NewFormatter

func NewFormatter(format Format) Formatter

NewFormatter creates appropriate formatter based on format.

type FormatterFunc

type FormatterFunc func(io.Writer, any) error

FormatterFunc allows functions to implement Formatter.

func (FormatterFunc) Format

func (f FormatterFunc) Format(w io.Writer, data any) error

Format implements the Formatter interface.

type JSONFormatter

type JSONFormatter struct {
	Indent string
}

JSONFormatter outputs JSON format.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(w io.Writer, data any) error

Format implements the Formatter interface for JSON output.

type TableFormatter

type TableFormatter struct {
	Wide bool
}

TableFormatter outputs table format.

func (*TableFormatter) Format

func (f *TableFormatter) Format(w io.Writer, data any) error

Format outputs data in table format.

type YAMLFormatter

type YAMLFormatter struct{}

YAMLFormatter outputs YAML format.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(w io.Writer, data any) error

Format outputs data in YAML format.

Jump to

Keyboard shortcuts

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