output

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFormat

func BoolFormat(val interface{}) (text.Colors, string, error)

BoolFormat returns val formatted as a boolean

func Render

func Render(writer io.Writer, cfg *config.Config, 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

func (Combined) MarshalYAML

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

MarshalYAML returns table output marshaled to YAML.

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

func (Details) MarshalYAML

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

MarshalYAML marshals details and returns the YAML as []byte nb. does *not* implement yaml.Marshaler

type Error

type Error struct {
	Value error
}

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

func (Error) MarshalYAML

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

MarshalYAML implements output.Output, it marshals the value and returns the YAML as []byte nb. does *not* implement yaml.Marshaler

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

func (MarshaledWithHumanDetails) MarshalYAML

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

MarshalYAML implements output.Output, it marshals the value and returns the YAML as []byte nb. does *not* implement yaml.Marshaler

type MarshaledWithHumanOutput added in v1.4.0

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 added in v1.4.0

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 added in v1.4.0

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

MarshalJSON implements json.Marshaler and output.Output

func (MarshaledWithHumanOutput) MarshalRawMap added in v1.4.0

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

MarshalRawMap implements output.Output

func (MarshaledWithHumanOutput) MarshalYAML added in v1.4.0

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

MarshalYAML implements output.Output, it marshals the value and returns the YAML as []byte nb. does *not* implement yaml.Marshaler

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

func (None) MarshalYAML

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

MarshalYAML 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

func (OnlyMarshaled) MarshalYAML

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

MarshalYAML implements output.Output, it marshals the value and returns the YAML as []byte nb. does *not* implement yaml.Marshaler

type Output

type Output interface {
	json.Marshaler
	MarshalYAML() ([]byte, error)
	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

func (Raw) MarshalYAML

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

MarshalYAML implements output.Output

type Table

type Table struct {
	Columns    []TableColumn
	Rows       []TableRow
	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

func (Table) MarshalYAML

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

MarshalYAML returns table output marshaled to YAML.

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