output

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONToYAML

func JSONToYAML(jsonIn []byte) ([]byte, error)

JSONToYAML converts JSON bytes into YAML bytes. This allows using key names from JSON field tags also for YAML output. This has some side-effects (e.g., timestamps will be double-quoted in output) but this is lesser evil than adding yaml field tags everywhere in our Go types.

func Render

func Render(writer io.Writer, outputFormat string, commandOutputs ...Output) (err error)

Render renders commandOutput to writer using cfg to configure the output.

Types

type Combined

type Combined []CombinedSection

Combined represents multiple outputs combined and displayed sequentially (or wrapped into the same object)

func (Combined) MarshalHuman

func (m Combined) MarshalHuman() ([]byte, error)

MarshalHuman returns output in a human-readable form

func (Combined) MarshalJSON

func (m Combined) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Combined) MarshalRawMap

func (m Combined) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type CombinedSection

type CombinedSection struct {
	Key      string
	Title    string
	Contents Output
}

CombinedSection represents a single section of a combined output

type DetailRow

type DetailRow struct {
	Title  string // used for human-readable representations
	Key    string // user for machine-readable (json, yaml) representations
	Value  interface{}
	Colour text.Colors
	Format func(val interface{}) (text.Colors, string, error)
}

DetailRow represents a single row in the details view, with a title and a value

type DetailSection

type DetailSection struct {
	Title string // used for human-readable representations
	Key   string // user for machine-readable (json, yaml) representations
	Rows  []DetailRow
}

DetailSection represents a section in the details view

func (DetailSection) MarshalJSON

func (d DetailSection) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type Details

type Details struct {
	Sections []DetailSection
}

Details implements output.Output for a details-style view

func (Details) MarshalHuman

func (d Details) MarshalHuman() ([]byte, error)

MarshalHuman marshals details and returns a human readable []byte

func (Details) MarshalJSON

func (d Details) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Details) MarshalRawMap

func (d Details) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type Error

type Error struct {
	Value    error
	Resolved string
	Original string
}

Error implements output.Command for a return value that is an error

func (Error) MarshalHuman

func (e Error) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler and output.Output

func (Error) MarshalRawMap

func (e Error) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type MarshaledWithHumanDetails

type MarshaledWithHumanDetails struct {
	Value   interface{}
	Details []DetailRow
}

MarshaledWithHumanDetails implements output.Command for a return value that is displayed as raw marshaled in JSON and YAML or as human details, such as UUID or IP address, eg. most create commands.

func (MarshaledWithHumanDetails) MarshalHuman

func (d MarshaledWithHumanDetails) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output For MarshaledWithHumanDetails outputs, we return *only* the details part in humanized output

func (MarshaledWithHumanDetails) MarshalJSON

func (d MarshaledWithHumanDetails) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler and output.Output

func (MarshaledWithHumanDetails) MarshalRawMap

func (d MarshaledWithHumanDetails) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type MarshaledWithHumanOutput

type MarshaledWithHumanOutput struct {
	Value  interface{}
	Output Output
}

MarshaledWithHumanOutput implements output.Command for a return value that passes through raw marshaled JSON or YAML and only affects human output. Like MarshaledWithHumanDetails, but allows more complex output.

func (MarshaledWithHumanOutput) MarshalHuman

func (d MarshaledWithHumanOutput) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output For MarshaledWithHumanDetails outputs, we return *only* the details part in humanized output

func (MarshaledWithHumanOutput) MarshalJSON

func (d MarshaledWithHumanOutput) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler and output.Output

func (MarshaledWithHumanOutput) MarshalRawMap

func (d MarshaledWithHumanOutput) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type None

type None struct{}

None is used when the command returns no output

func (None) MarshalHuman

func (s None) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output

func (None) MarshalJSON

func (s None) MarshalJSON() ([]byte, error)

MarshalJSON implements output.Output

func (None) MarshalRawMap

func (s None) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type OnlyMarshaled

type OnlyMarshaled struct {
	Value interface{}
}

OnlyMarshaled implements output.Command for a return value that is only displayed as raw marshaled in JSON and YAML eg. most 'state change' commands

func (OnlyMarshaled) MarshalHuman

func (d OnlyMarshaled) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output For OnlyMarshaled outputs, we dont return anything in humanized output as it's assumed the log output is what the user wants and it is down to the command itself to provide that.

func (OnlyMarshaled) MarshalJSON

func (d OnlyMarshaled) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler and output.Output

func (OnlyMarshaled) MarshalRawMap

func (d OnlyMarshaled) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type Output

type Output interface {
	json.Marshaler
	MarshalHuman() ([]byte, error)
	MarshalRawMap() (map[string]interface{}, error)
}

Output represent output from a command that can be rendered as JSON, YAML or human-readable

type Raw

type Raw []byte

Raw is a way to output raw data to the user. It is *only* supported in humanized output and used for generating shell completion scripts.

func (Raw) MarshalHuman

func (s Raw) MarshalHuman() ([]byte, error)

MarshalHuman implements output.Output

func (Raw) MarshalJSON

func (s Raw) MarshalJSON() ([]byte, error)

MarshalJSON implements output.Output

func (Raw) MarshalRawMap

func (s Raw) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type Table

type Table struct {
	Columns      []TableColumn
	Rows         []TableRow
	EmptyMessage string
	HideHeader   bool
}

Table represents command output rendered as a table

func (Table) MarshalHuman

func (s Table) MarshalHuman() ([]byte, error)

MarshalHuman returns table output in a human-readable form

func (Table) MarshalJSON

func (s Table) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Table) MarshalRawMap

func (s Table) MarshalRawMap() (map[string]interface{}, error)

MarshalRawMap implements output.Output

type TableColumn

type TableColumn struct {
	Header string
	Key    string
	Hidden bool

	Colour text.Colors
	Format func(val interface{}) (text.Colors, string, error)
	// contains filtered or unexported fields
}

TableColumn defines how a particular column is rendered

type TableRow

type TableRow []interface{}

TableRow represents a single row of data in a table

Jump to

Keyboard shortcuts

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