output

package
v0.26.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 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"
)

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

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

	// 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