github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/util/progress/multiwriter.go (about) 1 package progress 2 3 import ( 4 "strings" 5 6 "github.com/moby/buildkit/client" 7 ) 8 9 func WithPrefix(w Writer, pfx string, force bool) Writer { 10 return &prefixed{ 11 Writer: w, 12 pfx: pfx, 13 force: force, 14 } 15 } 16 17 type prefixed struct { 18 Writer 19 pfx string 20 force bool 21 } 22 23 func (p *prefixed) Write(v *client.SolveStatus) { 24 if p.force { 25 for _, v := range v.Vertexes { 26 v.Name = addPrefix(p.pfx, v.Name) 27 if v.ProgressGroup != nil { 28 v.ProgressGroup.Name = addPrefix(p.pfx, v.ProgressGroup.Name) 29 } 30 } 31 } 32 p.Writer.Write(v) 33 } 34 35 func addPrefix(pfx, name string) string { 36 if strings.HasPrefix(name, "[") { 37 return "[" + pfx + " " + name[1:] 38 } 39 return "[" + pfx + "] " + name 40 }