output

package
v0.68.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package output provides display and formatting capabilities to show the result of command's execution (command output)

Index

Constants

View Source
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 = "    "
)
View Source
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 GetOutWriter

func GetOutWriter(cmd *cobra.Command) io.Writer

func PrintCmdOutput

func PrintCmdOutput(cmd *cobra.Command, v any)

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

func PrintCmdOutputCustom(cmd *cobra.Command, v any, table *Table)

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

func PrintCmdStatus(cmd *cobra.Command, s string)

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

func PrintJson

func PrintJson(cmd *cobra.Command, v any) error

PrintJson displays the output in prettified JSON

func PrintYaml

func PrintYaml(cmd *cobra.Command, v any) error

PrintYaml displays the output in YAML

func WriteJson added in v0.31.0

func WriteJson(obj interface{}, w io.Writer) error

func WriteYaml added in v0.65.0

func WriteYaml(obj interface{}, w io.Writer) error

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
}

Jump to

Keyboard shortcuts

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