❯ go-clikit
v0.10.0 pkg.go.dev ↗

packages › progress & output › progress

progress

import "github.com/GSI-HPC/go-clikit/progress"

Report work as spans in a context.Context, and write the JSONL event log. The package draws nothing.

since v0.1.0 imports: termtext decisions 5 · 12 · 13 · 23 · 44
The place of progress in go-clikit: the packages it imports, and the packages that import it.termtextprogressdisplaycliprogressprogresstestmcpprogresseventlogfanoutfanouttestclioutdoctorfsutilcobratreecobratreetestlocalwebsessionsselocalwebtestlaunchassetspagehtmx

progress is the vocabulary that every other package of the kit speaks. Work is a tree of spans: the command, its steps, the batches, the targets, the calls and the waits. A span travels in the context.Context of the work. Each change of a span is one event, sent in one total order to the sinks of the Bus in the context.

command reinstallstep reinstalling…exe01exe02exe03Busdisplay.Treeprogress.Logprogresstest.Capture
Each change is one event. The Bus sends it to every sink in one order: a display, the event log, a test.

Use it#

A library takes a context, and starts spans in it with progress.Start. Without a Bus, Start returns a nil span whose methods do nothing, at no cost. A command attaches a Bus with progress.WithBus, or lets cliprogress do it.

bus := progress.NewBus(progress.BusOptions{Sinks: []progress.Sink{printer{}}})
ctx, command := progress.Start(progress.WithBus(context.Background(), bus), progress.KindCommand, "power reset")
command.End(reset(ctx, []string{"exe01", "exe02"}))
bus.Close()
1 start command "power reset" running
2 start step "reset the machines" running
3 start target "exe01" queued
4 start target "exe02" queued
5 run target "exe01" running
6 end target "exe01" ended ok
7 run target "exe02" running
8 end target "exe02" ended failed (target): exe02: no answer
9 end step "reset the machines" ended failed (target): exe02: no answer
10 end command "power reset" ended failed (target): exe02: no answer
Example in progress/example_test.go. CI runs it and checks its output.

The main names#

NameWhat it is
progress.Start, progress.Spana span: Run, Update, Advance, SetAmount, Skip, End
progress.Kindcommand, step, batch, target, call, wait
progress.Bus, progress.BusOptionssends the events, in one order, to the sinks
progress.Event, progress.Fieldsone change of a span, as plain data; the closed vocabulary
progress.Sinkwhat a display, a log or a test is
progress.NewLog, progress.LogOptionsthe JSONL event log
progress.Meter, progress.Readingthe work of each span, rolled up the tree
progress.Classify, progress.Skipthe class of an error; a target left out on purpose
progress.Suspendtakes every display off the terminal for a question
progress.ParseTraceContextcontinues the W3C trace of another program

Fixed interfaces#

  • The six span kinds.
  • The JSONL event log, version 1: keys can be added, and are never renamed or removed. See the event log.
  • No allocation without a Bus. A test of the kit keeps it so.

Read more#

Spans and the Bus and Work and the Meter explain the model.