output

package
v0.1.21758115741 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPadding specifies the number of spaces between columns in a table.
	DefaultPadding = 2

	// DefaultWriter specifies the output io.Writer for the Table.Print method.
	DefaultWriter io.Writer = os.Stdout

	// DefaultHeaderFormatter specifies the default Formatter for the table header.
	DefaultHeaderFormatter Formatter
)

These are the default properties for all Tables created from this package and can be modified.

Functions

func AddOutputAndQueryFlags

func AddOutputAndQueryFlags(cmd *cobra.Command)

func DefaultValueFormatter

func DefaultValueFormatter(columnIndex int, width int, val interface{}) string

func DefaultWidthFunc

func DefaultWidthFunc(value interface{}) int

func GetOutputAndQueryValues

func GetOutputAndQueryValues(cmd *cobra.Command, defaultQuery string) (string, string, error)
func GetTerminalLink(url string, displayText string) string

func OutputResult

func OutputResult(w io.Writer, result interface{}, outputFormat string, query string, defaultTableFields []string) error

func RoundtripMarshal

func RoundtripMarshal(data interface{}) ([]interface{}, error)

RoundtripMarshal marshals and unmarshals the data so that properties match the JSON property names

Types

type Formatter

type Formatter func(int, int, interface{}) string

Formatter is a function that formats a cell value for a table. The first argument is the column index The second argument is the width of the column The third argument is the value to format

type OutputFormat

type OutputFormat string
const (
	OutputJson      OutputFormat = "json"
	OutputJsonC     OutputFormat = "jsonc"
	OutputTsv       OutputFormat = "tsv"
	OutputTable     OutputFormat = "table"
	OutputTableBody OutputFormat = "tablebody"
)
type OutputLink struct {
	Text string
	Link string
}
func DecodeOutputLink(encodedValue string) *OutputLink

func (OutputLink) Encode

func (ol OutputLink) Encode() string

type Table

type Table interface {
	WithHeaderFormatter(f Formatter) Table
	WithValueFormatter(f Formatter) Table
	WithPadding(p int) Table
	WithWriter(w io.Writer) Table
	WithWidthFunc(f WidthFunc) Table

	AddRow(vals ...interface{}) Table
	Print() error
	PrintRows() error
}

func NewTable

func NewTable(columnHeaders ...interface{}) Table

New creates a Table instance with the specified header(s) provided. The number of columns is fixed at this point to len(columnHeaders) and the defined defaults are set on the instance.

type WidthFunc

type WidthFunc func(interface{}) int

Jump to

Keyboard shortcuts

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