output

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelQuiet   = Level(-1)
	LevelNormal  = Level(0)
	LevelVerbose = Level(1)
	LevelDebug   = Level(2)
)

Output levels

View Source
const (
	StdObjectFormatYAML = StdObjectFormat(0)
	StdObjectFormatJSON = StdObjectFormat(1)
)

Standard output interface object formats

Variables

This section is empty.

Functions

func NewLineWriter

func NewLineWriter(writeln func(line string)) io.WriteCloser

NewLineWriter creates a new line-segmented writer

func ReplayFromJSON

func ReplayFromJSON(r io.Reader, in *Interface, result interface{})

ReplayFromJSON reads the output from a JSON output interface and replays it on another output interface, optionally capturing the result in an output object

Types

type Handler

type Handler interface {
	Message(level Level, format string, v ...interface{})
	Warning(format string, v ...interface{})
	Error(format string, v ...interface{})
	Prompt(format string, v ...interface{}) bool
	Start(format string, v ...interface{}) Operation
	NewWriter(label string, level Level, err bool) io.WriteCloser
	Object(level Level, o interface{})
	Result(o interface{})
	io.Closer
}

Handler represents an output interface handler

type Interface

type Interface struct {
	Level
	// contains filtered or unexported fields
}

Interface represents an output interface

func NewInterface

func NewInterface(level Level, handler Handler) *Interface

NewInterface creates a new output interface

func NewJSONInterface

func NewJSONInterface(level Level, yes bool, out io.Writer) *Interface

NewJSONInterface creates a new output interface that marshals JSON objects as lines to a writer

func NewLogger

func NewLogger(level Level, format string, utc bool, w io.Writer) *Interface

NewLogger creates a new standard output interface that prefixes a timestamp to each line of output

func NewStdInterface

func NewStdInterface(level Level, opt *StdOptions, out io.Writer, err io.Writer) *Interface

NewStdInterface creates a new output interface that formats output to standard output and error writers

func (*Interface) Close

func (in *Interface) Close() error

Close closes the output interface

func (*Interface) Debug

func (in *Interface) Debug(format string, v ...interface{})

Debug outputs a diagnostic message

func (*Interface) Do

func (in *Interface) Do(format string, v ...interface{}) error

Do performs an operation

func (*Interface) Error

func (in *Interface) Error(format string, v ...interface{})

Error outputs an error message

func (*Interface) Info

func (in *Interface) Info(format string, v ...interface{})

Info outputs an informational message

func (*Interface) NewStream

func (in *Interface) NewStream(label string, level Level, err bool) *Stream

NewStream creates a new output stream

func (*Interface) Object

func (in *Interface) Object(level Level, o interface{})

Object outputs an object

func (*Interface) Prompt

func (in *Interface) Prompt(format string, v ...interface{}) bool

Prompt asks an interactive user to answer a question, or for non-interactive sessions, returns a pre-configured response

func (*Interface) Result

func (in *Interface) Result(o interface{})

Result returns a result object

func (*Interface) Start

func (in *Interface) Start(format string, v ...interface{}) Operation

Start reports the start of an operation

func (*Interface) Verbose

func (in *Interface) Verbose(format string, v ...interface{})

Verbose outputs a detailed message

func (*Interface) Warning

func (in *Interface) Warning(format string, v ...interface{})

Warning outputs a warning message

type Level

type Level int

Level represents an output level

func (Level) Is

func (l Level) Is(level Level) bool

Is indicates if the level matches a level

type MultiWriter

type MultiWriter interface {
	Attach(w io.Writer)
	Detach(w io.Writer)
	io.Writer
}

MultiWriter represents a writer that duplicates its writes to a set of writers that can be dynamically attached and detached

func NewMultiWriter

func NewMultiWriter(w ...io.Writer) MultiWriter

NewMultiWriter creates a new multi writer with an initial set of attached writers

type Operation

type Operation interface {
	Progress(format string, v ...interface{})
	Aborted()
	Failed()
	Done()
}

Operation represents an output operation

type StdObjectFormat

type StdObjectFormat int

StdObjectFormat represents a standard output interface object format

type StdOptions

type StdOptions struct {
	AcceptPrompts bool
	ObjectFormat  StdObjectFormat
}

StdOptions represents standard output interface options

type Stream

type Stream struct {
	Label string
	Level
	Err bool
	// contains filtered or unexported fields
}

Stream represents an output stream

func (*Stream) Close

func (s *Stream) Close() error

Close flushes and closes the output stream

func (*Stream) Write

func (s *Stream) Write(p []byte) (n int, err error)

Write writes data to the output stream

Jump to

Keyboard shortcuts

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