Documentation ¶
Index ¶
- Constants
- func AddProgressBarFlags(cmd *cobra.Command)
- func Bulletf(template string, vs ...any) bulletf
- func CollectionProgress(ctx context.Context, category string, dirName any) chan<- struct{}
- func Flush(ctx context.Context)
- func ItemProgress(ctx context.Context, rc io.ReadCloser, header string, iname any, ...) io.ReadCloser
- func ItemSpinner(ctx context.Context, rc io.ReadCloser, header string, iname any) io.ReadCloser
- func Message(ctx context.Context, cfg ProgressCfg, msgs ...any)
- func MessageWithCompletion(ctx context.Context, cfg ProgressCfg, msgs ...any) chan<- struct{}
- func PreloadFlags() config
- func ProgressWithCount(ctx context.Context, header string, msg any, count int64) chan<- struct{}
- func SeedObserver(ctx context.Context, w io.Writer, cfg config) context.Context
- type ProgressCfg
Constants ¶
const ( ItemBackupMsg = "Backing up item" ItemRestoreMsg = "Restoring item" ItemExportMsg = "Exporting item" ItemQueueMsg = "Queuing items" )
const Bullet = "∙"
Variables ¶
This section is empty.
Functions ¶
func AddProgressBarFlags ¶
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 CollectionProgress ¶
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 ¶
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 ¶
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.
Types ¶
type ProgressCfg ¶
type ProgressCfg struct { NewSection bool SectionIdentifier any Indent int CompletionMessage func() string }
func DefaultCfg ¶
func DefaultCfg() ProgressCfg