feedback

package
v0.0.0-...-fc75a81 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatal

func Fatal(errorMsg string, exitCode ExitCode)

Fatal outputs the errorMsg and exits with status exitCode.

func FatalError

func FatalError(err error, exitCode ExitCode)

FatalError outputs the error and exits with status exitCode.

func FatalResult

func FatalResult(res ErrorResult, exitCode ExitCode)

FatalResult outputs the result and exits with status exitCode.

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 SetFormat

func SetFormat(f OutputFormat)

SetFormat can be used to change the output format at runtime

Types

type ErrorResult

type ErrorResult interface {
	Result
	ErrorString() string
}

ErrorResult is a result embedding also an error. In case of textual output the error will be printed on stderr.

type ExitCode

type ExitCode int

ExitCode to be used for Fatal.

const (
	// Success (0 is the no-error return code in Unix)
	Success ExitCode = iota

	// ErrGeneric Generic error (1 is the reserved "catchall" code in Unix)
	ErrGeneric

	// ErrNoConfigFile is returned when the config file is not found (3)
	ErrNoConfigFile

	// ErrNetwork is returned when a network error occurs (5)
	ErrNetwork

	// ErrCoreConfig represents an error in the cli core config, for example some basic
	// files shipped with the installation are missing, or cannot create or get basic
	// directories vital for the CLI to work. (6)
	ErrCoreConfig

	// ErrBadArgument is returned when the arguments are not valid (7)
	ErrBadArgument
)

type OutputFormat

type OutputFormat int

OutputFormat is an output format

const (
	// Text is the plain text format, suitable for interactive terminals
	Text OutputFormat = iota
	// JSON format
	JSON
)

func GetFormat

func GetFormat() OutputFormat

GetFormat returns the output format currently set

func ParseOutputFormat

func ParseOutputFormat(in string) (OutputFormat, bool)

ParseOutputFormat parses a string and returns the corresponding OutputFormat. The boolean returned is true if the string was a valid OutputFormat.

func (OutputFormat) String

func (f OutputFormat) String() string

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