format

package
v1.202.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 19 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"
	CompactColumnMaxWidth     = 20 // Maximum width for non-Description columns.
	DescriptionColumnMinWidth = 30 // Minimum width for Description column.
	MinColumnWidth            = 5  // Absolute minimum width for any column.

)

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. Uses intelligent column width calculation to optimize space usage.

func RenderInstancesTree added in v1.201.0

func RenderInstancesTree(stacksWithComponents map[string]map[string][]*listtree.ImportNode, showImports bool) string

RenderInstancesTree renders stacks with their components and import hierarchies as a tree. Structure: Stacks → Components → Imports. If showImports is false, only shows stacks and components without import details.

func RenderStacksTree added in v1.201.0

func RenderStacksTree(stacksWithImports map[string][]*listtree.ImportNode, showImports bool) string

RenderStacksTree renders stacks with their import hierarchies as a tree. If showImports is false, only stack names are shown without import details.

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"
	FormatTree     Format = "tree"
)

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