Documentation
¶
Overview ¶
Package output renders command results in the format the caller asked for.
Every command produces a Result holding the same information three ways: a table for a terminal, an object for a machine, and, where it makes sense, a node set. The format flag then picks one. A command never formats its own output, so -o json means the same thing everywhere.
Index ¶
Constants ¶
const ( FormatTable = "table" FormatWide = "wide" FormatJSON = "json" FormatYAML = "yaml" FormatNodeset = "nodeset" FormatName = "name" FormatJQ = "jq" )
The output formats -o accepts.
Variables ¶
This section is empty.
Functions ¶
func EscapeCell ¶ added in v0.3.0
EscapeCell is termtext.EscapeCell: untrusted text made safe for one line of a terminal.
func EscapeText ¶ added in v0.3.0
EscapeText is termtext.EscapeText: untrusted text made safe for a terminal, its lines kept.
Types ¶
type Column ¶
type Column struct {
// Name is the heading, upper case by convention.
Name string
// Wide keeps the column out of the default table and shows it only
// under -o wide.
Wide bool
// Right aligns the values to the right, for counts.
Right bool
}
Column is one column of a table.
type Columns ¶ added in v0.4.0
type Columns []Column
Columns are the headings of a table: plain ones from Cols, marked by Wide and Right.
type Format ¶
type Format struct {
// Kind is one of the format constants.
Kind string
// Arg is the program of the jq format.
Arg string
}
Format is a parsed -o value.
func ParseFormat ¶
ParseFormat reads a -o value. A jq program is compiled here, so that a mistake in it is reported before a command has acted rather than when its result is printed.
func (Format) IsMachine ¶
IsMachine reports whether the format is meant to be parsed by a program, which is when the decoration of standard output, such as a note between the rows, is left out. Progress has nothing to do with it: it is only ever drawn on standard error, whatever the format.
type Result ¶
type Result struct {
// Table is rendered by the table and wide formats.
Table *Table
// Object is rendered by the json, yaml and jq formats. When it is nil the
// table is converted to a list of objects.
Object any
// Nodes is rendered by the nodeset and name formats. When it is nil
// those formats fall back to the first column of the table.
Nodes *nodeset.NodeSet
}
Result is what a command produces, in every shape the formats need.
type Table ¶
type Table struct {
Columns []Column
Rows [][]string
// Caption is printed under the table, for a total or a note.
Caption string
}
Table is a command result in rows and columns. Values are never truncated: a long reason or a wide node set is worth a wrapped line, and truncation has hidden the important half of a message often enough.