format

package
v0.16.5 Latest Latest
Warning

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

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

Documentation

Overview

Package format provides common output formatting utilities for CLI commands.

Package format renders command output.

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 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 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 Kind added in v0.2.0

type Kind string

Kind identifies an output format.

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

func DetectFormat

func DetectFormat(explicitFormat string) Kind

DetectFormat auto-detects format based on terminal and environment.

func ParseFormat

func ParseFormat(s string) (Kind, error)

ParseFormat converts a string to Kind with validation.

type Renderer added in v0.2.0

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

Renderer writes a value in one output format.

func New added in v0.2.0

func New(kind Kind) Renderer

New returns the renderer for kind.

type RendererFunc added in v0.2.0

type RendererFunc func(io.Writer, any) error

RendererFunc allows functions to implement Renderer.

func (RendererFunc) Format added in v0.2.0

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

Format implements Renderer.

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