Documentation
¶
Overview ¶
Package printer provides output formatting utilities for the CLI
Package printer provides output formatting utilities for the CLI
Index ¶
- func Print(res any, pageIndex, pageCount, itemCount int64, showPagination bool, ...) error
- func PrintJsonWithOptions(res any, options JsonOptions) error
- func PrintTableWithOptions(res any, options TableOptions) error
- func PrintWithOptions(res any, options PrintOptions) error
- type ColumnMapping
- type JsonOptions
- type PrintOptions
- type TableOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Print ¶
func Print(res any, pageIndex, pageCount, itemCount int64, showPagination bool, mappings [][]string) error
Print formats and outputs data based on the global format setting This function is backward compatible with existing code
func PrintJsonWithOptions ¶
func PrintJsonWithOptions(res any, options JsonOptions) error
PrintJsonWithOptions prints the provided data as JSON with the specified options
Example:
options := printer.DefaultJsonOptions() options.Indent = true options.ShowPagination = true printer.PrintJsonWithOptions(results, options)
func PrintTableWithOptions ¶
func PrintTableWithOptions(res any, options TableOptions) error
PrintTableWithOptions prints the data in a table format using the provided options
func PrintWithOptions ¶
func PrintWithOptions(res any, options PrintOptions) error
PrintWithOptions formats and outputs data using the provided options
Types ¶
type ColumnMapping ¶
type ColumnMapping [][]string
ColumnMapping defines a mapping between original field names and display names
type JsonOptions ¶
type JsonOptions struct {
// Writer is the output destination (defaults to os.Stdout if nil)
Writer io.Writer
// Indent specifies if pretty-printing should be used
Indent bool
// IndentPrefix is the prefix used at the beginning of each line in the indented output
IndentPrefix string
// IndentSize is the number of spaces used for each indentation level
IndentSize int
// PageIndex is the current page number (zero-indexed)
PageIndex int64
// PageCount is the total number of pages
PageCount int64
// ItemCount is the total number of items
ItemCount int64
// ShowPagination determines whether to show pagination info
ShowPagination bool
}
JsonOptions provides configuration for the JSON output
func DefaultJsonOptions ¶
func DefaultJsonOptions() JsonOptions
DefaultJsonOptions returns standard options for JSON printing
type PrintOptions ¶
type PrintOptions struct {
// Format specifies the output format ("json" or "table")
Format string
// Writer is the output destination (defaults to os.Stdout if nil)
Writer io.Writer
// PageIndex is the current page number (zero-indexed)
PageIndex int64
// PageCount is the total number of pages
PageCount int64
// ItemCount is the total number of items
ItemCount int64
// ShowPagination determines if pagination information should be displayed
ShowPagination bool
// JsonIndent specifies if JSON should be pretty-printed
JsonIndent bool
// ColumnMapping defines custom column ordering and display names for table format
// Format: [["originalField", "Display Name"], ...]
ColumnMapping ColumnMapping
}
PrintOptions combines options for both JSON and table output
func DefaultPrintOptions ¶
func DefaultPrintOptions() PrintOptions
DefaultPrintOptions returns standard print options using the global config
type TableOptions ¶
type TableOptions struct {
// ColumnMapping defines custom column ordering and display names
// Format: [["originalField", "Display Name"], ...]
ColumnMapping ColumnMapping
// PageIndex is the current page number (zero-indexed)
PageIndex int64
// PageCount is the total number of pages
PageCount int64
// ItemCount is the total number of items
ItemCount int64
// ShowPagination determines whether to show pagination info
ShowPagination bool
}
TableOptions provides configuration for table output
func DefaultTableOptions ¶
func DefaultTableOptions() TableOptions
DefaultTableOptions returns default configuration for table printing