feedback

package
v0.0.0-...-20dd7c9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(v ...interface{})

Error behaves like fmt.Print but writes on the error writer and adds a newline. It also logs the error.

func ErrorWriter

func ErrorWriter() io.Writer

ErrorWriter is the same as OutputWriter but exposes the underlying error writer

func Errorf

func Errorf(format string, v ...interface{})

Errorf behaves like fmt.Printf but writes on the error writer and adds a newline. It also logs the error.

func OutputWriter

func OutputWriter() io.Writer

OutputWriter returns the underlying io.Writer to be used when the Print* api is not enough

func Print

func Print(v interface{})

Print behaves like fmt.Print but writes on the out writer and adds a newline.

func PrintResult

func PrintResult(res Result)

PrintResult is a convenient wrapper to provide feedback for complex data, where the contents can't be just serialized to JSON but requires more structure.

func Printf

func Printf(format string, v ...interface{})

Printf behaves like fmt.Printf but writes on the out writer and adds a newline.

func SetDefaultFeedback

func SetDefaultFeedback(f *Feedback)

SetDefaultFeedback lets callers override the default feedback object. Mostly useful for testing.

func SetErr

func SetErr(err io.Writer)

SetErr can be used to change the err writer at runtime

func SetFormat

func SetFormat(f OutputFormat)

SetFormat can be used to change the output format at runtime

func SetOut

func SetOut(out io.Writer)

SetOut can be used to change the out writer at runtime

Types

type Feedback

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

Feedback wraps an io.Writer and provides an uniform API the CLI can use to provide feedback to the users.

func DefaultFeedback

func DefaultFeedback() *Feedback

DefaultFeedback provides a basic feedback object to be used as default.

func New

func New(out, err io.Writer, format OutputFormat) *Feedback

New creates a Feedback instance

func (*Feedback) Error

func (fb *Feedback) Error(v ...interface{})

Error behaves like fmt.Print but writes on the error writer and adds a newline. It also logs the error.

func (*Feedback) ErrorWriter

func (fb *Feedback) ErrorWriter() io.Writer

ErrorWriter is the same as OutputWriter but exposes the underlying error writer.

func (*Feedback) Errorf

func (fb *Feedback) Errorf(format string, v ...interface{})

Errorf behaves like fmt.Printf but writes on the error writer and adds a newline. It also logs the error.

func (*Feedback) GetFormat

func (fb *Feedback) GetFormat() OutputFormat

GetFormat returns the output format currently set

func (*Feedback) OutputWriter

func (fb *Feedback) OutputWriter() io.Writer

OutputWriter returns the underlying io.Writer to be used when the Print* api is not enough.

func (*Feedback) Print

func (fb *Feedback) Print(v interface{})

Print behaves like fmt.Print but writes on the out writer and adds a newline.

func (*Feedback) PrintResult

func (fb *Feedback) PrintResult(res Result)

PrintResult is a convenient wrapper to provide feedback for complex data, where the contents can't be just serialized to JSON but requires more structure.

func (*Feedback) Printf

func (fb *Feedback) Printf(format string, v ...interface{})

Printf behaves like fmt.Printf but writes on the out writer and adds a newline.

func (*Feedback) SetErr

func (fb *Feedback) SetErr(err io.Writer)

SetErr can be used to change the err writer at runtime

func (*Feedback) SetFormat

func (fb *Feedback) SetFormat(f OutputFormat)

SetFormat can be used to change the output format at runtime

func (*Feedback) SetOut

func (fb *Feedback) SetOut(out io.Writer)

SetOut can be used to change the out writer at runtime

type OutputFormat

type OutputFormat int

OutputFormat is used to determine the output format

const (
	// Text means plain text format, suitable for ansi terminals
	Text OutputFormat = iota
	// JSON means JSON format
	JSON
	// JSONMini is identical to JSON but without whitespaces
	JSONMini
	// YAML means YAML format
	YAML
)

func GetFormat

func GetFormat() OutputFormat

GetFormat returns the currently set output format

type Result

type Result interface {
	fmt.Stringer
	Data() interface{}
}

Result is anything more complex than a sentence that needs to be printed for the user.

Jump to

Keyboard shortcuts

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