Documentation
¶
Overview ¶
Package table provides a simple API for outputting tabular data to stdout. It is used to implement --format=table.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a set of simple tabular data. Tables have a list of header cells and a list of rows. Each row must be the same length as the list of header cells. Tables can be formatted nicely to stdout. Construct a table with the New or FromStructs functions, and then use the AddRow, SortBy, and Print methods.
func FromStructs ¶
func FromStructs(structs interface{}) Table
FromStructs creates a new table from the given slice of structs. The table headers are generated from the struct field reflection metadata: each struct field must have a reflection metadata key "pretty" whose value is the header to display. The only allowed field types in the struct are string and []string. The strings are used as table cells directly, while the slices are concatenated with commas first.
func New ¶
New creates a new table with the given headers. The table has no rows; add them with AddRow. The headers should all be unique.
func (*Table) AddRow ¶
AddRow adds a row at the end of a table. The length of the row must be the same as the number of headers in the table, or a panic will be generated.
func (*Table) Print ¶
func (t *Table) Print()
Print writes the table to stdout, aligning columns by inserting whitespace. If the table is too wide for the current terminal, and the 'less' utility is installed, Print invokes it with the -S option to truncate long lines and allow horizontal scrolling.