output

package
v0.0.0-...-63b02d4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flatten

func Flatten(inputJSON interface{}) map[string]interface{}

Flatten accepts a nested struct and returns a flat struct with key like a.'b/c'.d[0].e

func PrintFlat

func PrintFlat(b []byte)

PrintFlat accepts a JSON formated byte array and prints to stdout the sorted "key = val"

func RelaxedJSONPathExpression

func RelaxedJSONPathExpression(pathExpression string) (string, error)

RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:

  • metadata.name (no leading '.' or curly braces '{...}'
  • {metadata.name} (no leading '.')
  • .metadata.name (no curly braces '{...}')
  • {.metadata.name} (complete expression)

And transforms them all into a valid jsonpath expression:

{.metadata.name}

func SprintFlat

func SprintFlat(b []byte) string

SprintFlat accepts a JSON formated byte array and returns the sorted "key = val" buffer

func SprintFlatColor

func SprintFlatColor(b []byte, colorize *palette.ColorPaletteFunc) string

Types

type RenderFunc

type RenderFunc func() string

RenderFunc is the protype of human format renderer functions.

type Renderer

type Renderer struct {
	DefaultOutput string
	Output        string
	Color         string
	Data          any
	HumanRenderer RenderFunc
	Colorize      *palette.ColorPaletteFunc
	Stream        bool
}

Renderer hosts the renderer options and data, and exposes the rendering method.

func (Renderer) Print

func (t Renderer) Print()

Print prints the representation of the data in one of the supported format (json, flat, human, ...).

The human format needs a RenderFunc to be passed.

func (Renderer) Sprint

func (t Renderer) Sprint() (string, error)

Sprint returns the string representation of the data in one of the supported format (json, flat, human, ...).

The human format needs a RenderFunc to be passed.

type T

type T int

T encodes as an integer one of the supported output formats (json, flat, human, table, csv)

const (
	// Human is the prefered human friendly custom output format
	Human T = iota
	// JSON is the json output format
	JSON
	// Flat is the flattened json output format (a.'b#b'.c = d, a[0] = b)
	Flat
	// JSONLine is unindented json output format
	JSONLine
	// Tab is the customizable tabular output format
	Tab
	// Table is the simple tabular output format
	Table
	// CSV is the csv tabular output format
	CSV
	// YAML is the standard human readable, commentable, complex data representation
	YAML
)

func New

func New(s string) T

New returns the integer value of the output format

func (T) MarshalText

func (t T) MarshalText() ([]byte, error)

MarshalText marshals the enum as a quoted json string

func (T) String

func (t T) String() string

func (*T) UnmarshalText

func (t *T) UnmarshalText(b []byte) error

UnmarshalText unmashals a quoted json string to the enum value

Jump to

Keyboard shortcuts

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