output

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

package output handles formatting output data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {

	// Format marshals the given data to the relevant format and then
	// writes it to the specified writer.
	Format(writer io.Writer, data interface{}) error

	// SetOption specifies an option to control how the handler should
	// behave. Setting options that the handler does not implement should
	// cause SetOption to return nil, this way the CLI handling logic does
	// not have to determine which handler is being used before deciding
	// which options to try to set.
	//
	// The following options should be supported by all output formatters
	// to the greatest extent possible:
	//
	// output:colorize (bool) if true, syntax highlight the output if
	// possible, otherwise do not do so (defaults to true)
	//
	// output:pretty (bool) if true, pretty-print the output if possible,
	// otherwise minify the output or otherwise leave in the default format
	// (defaults to true)
	//
	// output:indent (string) for formats such as JSON and YAML where
	// indenting is used, specify the indent character (defaults to '\t')
	//
	// output:style (string) specifies the Chroma format to use when
	// colorizing output (default: "native"); see:
	// https://xyproto.github.io/splash/docs/
	SetOption(name string, value interface{}) error

	// Name should return the name of this handler, e.g. "json" or "csv".
	Name() string
}

Handler represents a handler for one type of output format, such as JSON or CSV.

func SelectHandler

func SelectHandler(name string) (Handler, error)

SelectHandler chooses a handler based on the name provided.

If name is the empty string, then it default to "json".

type JSONHandler

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

JSONHandler handles parsing JSON data.

func (*JSONHandler) Format

func (j *JSONHandler) Format(writer io.Writer, data interface{}) error

Format implements Handler.Format()

func (*JSONHandler) Name

func (j *JSONHandler) Name() string

Name implements Handler.Name().

func (*JSONHandler) SetOption

func (j *JSONHandler) SetOption(name string, value interface{}) error

SetOption implements Handler.SetOption().

type YAMLHandler

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

YAMLHandler handles parsing YAML data.

YAMLHandler does not support output:pretty or output:indent, because go-yaml does not support modifying the indent behavior.

func (*YAMLHandler) Format

func (y *YAMLHandler) Format(writer io.Writer, data interface{}) error

Format implements Handler.Format()

func (*YAMLHandler) Name

func (y *YAMLHandler) Name() string

Name implements Handler.Name().

func (*YAMLHandler) SetOption

func (y *YAMLHandler) SetOption(name string, value interface{}) error

SetOption implements Handler.SetOption().

Jump to

Keyboard shortcuts

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