Documentation ¶
Overview ¶
Package output provides display and formatting capabilities to show the result of command's execution (command output)
Index ¶
- Constants
- func GetOutWriter(cmd *cobra.Command) io.Writer
- func PrintCmdOutput(cmd *cobra.Command, v any)
- func PrintCmdOutputCustom(cmd *cobra.Command, v any, table *Table)
- func PrintCmdStatus(cmd *cobra.Command, s string)
- func PrintJson(cmd *cobra.Command, v any) error
- func PrintYaml(cmd *cobra.Command, v any) error
- func WriteJson(obj interface{}, w io.Writer) error
- func WriteYaml(obj interface{}, w io.Writer) error
- type Table
Constants ¶
const ( // TableFieldsAnnotation is the name of the cobra.Command annotation to use to specify the fields JQ query for table output TableFieldsAnnotation = "output/tableFields" // DetailFieldsAnnotation is the name of the cobra.Command annotation to use to specify the fields JQ query for detail output DetailFieldsAnnotation = "output/detailFields" JsonIndent = " " )
const ( ALIGN_DEFAULT = tablewriter.ALIGN_DEFAULT ALIGN_CENTER = tablewriter.ALIGN_CENTER ALIGN_RIGHT = tablewriter.ALIGN_RIGHT ALIGN_LEFT = tablewriter.ALIGN_LEFT )
Variables ¶
This section is empty.
Functions ¶
func PrintCmdOutput ¶
PrintCmdOutput displays the output of a command in the user-selected output format. If a human display format is selected, PrintCmdOutput automatically converts the value to one of the supported formats (within limits); if it cannot be converted, YAML is displayed instead. If cmd is not provided or it has no `output` flag, human is assumed If human format is requested/assumed but no table is provided, displays YAML If the object cannot be converted to the desired format, shows the object in Go's %+v format
func PrintCmdOutputCustom ¶
PrintCmdOutputCustom displays the output of a command in the user-selected output format with the capability to provide custom output for the human display formats. If cmd is not provided or it has no `output` flag, human is assumed If human format is requested/assumed but no table is provided, displays YAML If the object cannot be converted to the desired format, shows the object in Go's %+v format
func PrintCmdStatus ¶
PrintCmdStatus displays a single string message to the command output Use this only for commands that don't display parseable data (e.g., "config set"), for example, to confirm that the operation was completed
Types ¶
type Table ¶
type Table struct { // table output Headers []string Lines [][]string Detail bool // true to print a single line as a name: value multi-line instead of table OmitHeaders bool // don't print the headers DisableAutoWrapText bool // try to keep each row on a single line as much as possible Alignment int // override the automatic alignment for all fields ColumnMinWidths [][]int // List of tuples (column index, min width) to apply via tw.SetColMinWidth // extract field columns in the same order as headers LineBuilder func(v any) []string // use together with Headers and no Lines }