output

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package output provides operations for command implementations to write information of various kinds.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoContext is returned when FromContext cannot find an output.Options in the context.
	ErrNoContext = errors.New("no output context found")
)

Functions

func AllowOverwrite

func AllowOverwrite(ctx context.Context) bool

AllowOverwrite returns true if --overwrite is true.

func AllowRecoverableError

func AllowRecoverableError(ctx context.Context) bool

AllowRecoverableError returns true if --keep_going is true.

func Debugf

func Debugf(ctx context.Context, format string, args ...any) (int, error)

Debugf writes a formatted string with a newline to the Debug modality.

func Errorf

func Errorf(ctx context.Context, format string, args ...any) (int, error)

Errorf writes a formatted string with a newline to the Output modality, prefixed by an error message.

func Infof

func Infof(ctx context.Context, format string, args ...any) (int, error)

Infof writes a formatted string with a newline to the Output modality.

func NewContext

func NewContext(ctx context.Context, opts *Options) context.Context

NewContext returns ctx extended with opts added.

func Warningf

func Warningf(ctx context.Context, format string, args ...any) (int, error)

Warningf writes a formatted string with a newline to the Output modality, prefixed by a warning message.

Types

type Options

type Options struct {
	Quiet     bool
	Verbose   bool
	UseLogs   bool
	Overwrite bool
	KeepGoing bool
	Out       io.Writer
	Err       io.Writer
}

Options controls the meaning of output modalities.

func FromContext

func FromContext(ctx context.Context) (*Options, error)

FromContext returns the Options value in ctx if it exists.

func (*Options) AddFlags

func (opts *Options) AddFlags(cmd *cobra.Command)

AddFlags adds flags specific to the Options object to the given command.

func (*Options) Validate

func (opts *Options) Validate(cmd *cobra.Command) error

Validate returns an error if the Options values are incompatible.

Jump to

Keyboard shortcuts

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