formatter

package
v1.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package formatter contains the logic to template the CLI output to a specific format

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetLoaderFunc

type AssetLoaderFunc func(name string) ([]byte, error)

AssetLoaderFunc loads and returns the asset for the given name. If an error is returned, the asset could not be found or could not be loaded.

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain implements the Chain interface

Allows the formatting responsibility to become a chain. It will cascade when formatter.Format returns an error and the next property contains another actionable chain (next != nil). When the Format is handled without error it will return immediately

func New

func New(o io.Writer, name string) *Chain

New initializes a ChainFormatter defaulting to the JSON Formatter if no known formatter is passed, else It will use the mentioned formatter and use the JSON Formatter to fallback when parsing the output fails.

func NewChain

func NewChain(f Formatter) *Chain

NewChain wraps a formatter into a Chain

func (*Chain) Add

func (f *Chain) Add(next Chainer) *Chain

Add adds a the next ChainFormatter to the chain

func (Chain) Format

func (f Chain) Format(path string, data interface{}) error

Format wraps the Format method of Formatter going down the chain when formatter.Format returns an error and the next property contains another actionable chain (next != nil). When the Format is handled without error it will return immediately

func (*Chain) Name

func (f *Chain) Name() string

Name obtains the name of the Formatter

type Chainer

type Chainer interface {
	Formatter
	// Add adds a the next ChainFormatter to the chain
	Add(Chainer) *Chain
}

Chainer implements the Single Chain of Responsibility Pattern, to be able to chain off multiple Formatters

type Formatter

type Formatter interface {
	// Format is used from the cmd, it receives the parent and the data to be
	// formatted. The path usually has an effect on how the data will end up
	// being represented.
	Format(path string, data interface{}) error
	// Name obtains the name of the Formatter
	Name() string
}

Formatter models the formatter actions

type JSON

type JSON struct {
	// contains filtered or unexported fields
}

JSON formats into text

func NewJSON

func NewJSON(output io.Writer) *JSON

NewJSON acts as the factory for formatter.JSON

func (*JSON) Format

func (f *JSON) Format(path string, data interface{}) error

Format is used from the cmd for conveniency it receives a path and the data to be formatted.

It currently doesn't have any effect on the JSON formatting due to `MarshalIndent` being used

func (*JSON) Name

func (f *JSON) Name() string

Name obtains the name of the formatter

type Text

type Text struct {
	// contains filtered or unexported fields
}

Text formats into text

func NewText

func NewText(c *TextConfig) *Text

NewText acts as the factory for formatter.Text

func (*Text) Format

func (f *Text) Format(path string, data interface{}) error

Format is used from the cmd for conveniency, it receives a path and the data which needs to be used in the template. Uses the name of the formatter as the first argument of the template name. If the asset is not found, it will default to defaultOverrideFormat

func (*Text) Name

func (f *Text) Name() string

Name obtains the name of the formatter

type TextConfig

type TextConfig struct {
	// Output device where the template execution will be written.
	Output io.Writer
	// Override is the format to be used for the commands that are sent
	Override string
	// Fallback base template to use when a file asset is not found in
	// "text/parent/child.gotmpl" unless specified `defaultOverrideFormat` is
	// used.
	Fallback string
	// Padding represents the number of spaces to use in between the text
	// columns.
	Padding int

	// AssetLoaderFunction is the asset loader function to be used. It must
	// return a byte encoded Go template parseable by template.Template.Parse.
	AssetLoaderFunction AssetLoaderFunc
}

TextConfig is the configuration to use for a text formatter

Directories

Path Synopsis
Package templates Code generated by go-bindata.
Package templates Code generated by go-bindata.

Jump to

Keyboard shortcuts

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