clitable

package
v0.0.0-...-5fb8a3f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package clitable implements tabular display for command line tools.

The generated tables are vaguely reminiscent of the output of 'kubectl'. For example:

NAME ADDRESS  STATUS
foo  1.2.3.4  Healthy
bar  1.2.3.12 Timeout

The tables are sparse by design, with each Entry having a number of Key/Value entries. Then, all keys for all entries get unified into columns, and entries without a given key are rendered spare (i.e. the rendered cell is empty).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	// contains filtered or unexported fields
}

A Column in a table, not containing all entries that make up this table, but containing their maximum width (for layout purposes).

type Columns

type Columns []*Column

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

An Entry is made up of column key -> value pairs.

func (*Entry) Add

func (e *Entry) Add(key, value string)

Add a key/value pair to the entry.

func (*Entry) Get

func (e *Entry) Get(key string) string

Get a value from a given key, returning zero string if not set.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a list of entries that form a table with sparse columns. Each entry defines its own columns.

func (*Table) Add

func (t *Table) Add(e Entry)

Add an entry to the table.

func (*Table) Columns

func (t *Table) Columns() Columns

Columns returns the keys and widths of columns that are present in the table's entries.

func (*Table) Print

func (t *Table) Print(f io.Writer, onlyColumns map[string]bool)

Print writes a table-like representation of this table to the given file, first filtering the columns by onlyColumns (if not set, no filtering takes place).

Jump to

Keyboard shortcuts

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