observe

package
v0.0.0-...-880cb89 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ItemBackupMsg  = "Backing up item"
	ItemRestoreMsg = "Restoring item"
	ItemExportMsg  = "Exporting item"
	ItemQueueMsg   = "Queuing items"
)
View Source
const Bullet = "∙"

Variables

This section is empty.

Functions

func AddProgressBarFlags

func AddProgressBarFlags(cmd *cobra.Command)

adds the persistent boolean flag --hide-progress to the provided command. This is a hack for help displays. Due to seeding the context, we also need to parse the configuration before we execute the command.

func Bulletf

func Bulletf(template string, vs ...any) bulletf

func CollectionProgress

func CollectionProgress(
	ctx context.Context,
	category string,
	dirName any,
) chan<- struct{}

CollectionProgress tracks the display a spinner that idles while the collection incrementing the count of items handled. Each write to the provided channel counts as a single increment. The caller is expected to close the channel.

func Flush

func Flush(ctx context.Context)

Flush blocks until the progress finishes writing out all data. Afterwards, the progress instance is reset.

func ItemProgress

func ItemProgress(
	ctx context.Context,
	rc io.ReadCloser,
	header string,
	iname any,
	totalBytes int64,
) io.ReadCloser

ItemProgress tracks the display of an item in a folder by counting the bytes read through the provided readcloser, up until the byte count matches the totalBytes.

The progress bar will close automatically when the reader closes. If an early close is needed due to abort or other issue, the reader can be closed manually.

func ItemSpinner

func ItemSpinner(
	ctx context.Context,
	rc io.ReadCloser,
	header string,
	iname any,
) io.ReadCloser

ItemSpinner is similar to ItemProgress, but for use in cases where we don't know the file size but want to show progress.

The progress bar will close automatically when the reader closes. If an early close is needed due to abort or other issue, the reader can be closed manually.

func Message

func Message(ctx context.Context, cfg ProgressCfg, msgs ...any)

Message is used to display a progress message

func MessageWithCompletion

func MessageWithCompletion(
	ctx context.Context,
	cfg ProgressCfg,
	msgs ...any,
) chan<- struct{}

MessageWithCompletion is used to display progress with a spinner that switches to "done" when the completion channel is signalled

func PreloadFlags

func PreloadFlags() config

Due to races between the lazy evaluation of flags in cobra and the need to init observer behavior in a ctx, these options get pre-processed manually here using pflags. The canonical AddProgressBarFlag() ensures the flags are displayed as part of the help/usage output.

func ProgressWithCount

func ProgressWithCount(
	ctx context.Context,
	header string,
	msg any,
	count int64,
) chan<- struct{}

ProgressWithCount tracks the display of a bar that tracks the completion of the specified count. Each write to the provided channel counts as a single increment. The caller is expected to close the channel.

func SeedObserver

func SeedObserver(ctx context.Context, w io.Writer, cfg config) context.Context

SeedObserver adds an observer to the context. Any calls to observe funcs will retrieve the observer from the context. If no observer is found in the context, the call no-ops.

Types

type ProgressCfg

type ProgressCfg struct {
	NewSection        bool
	SectionIdentifier any
	Indent            int
	CompletionMessage func() string
}

func DefaultCfg

func DefaultCfg() ProgressCfg

Jump to

Keyboard shortcuts

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