Files
trivy/pkg/indicator/progress.go
Teppei Fukuda cee08c38f4 feat(db): show progress when downloading the DB (#317)
* fix(github): return db size

* fix(github_mock): add size

* feat(indicator): add progress bar

* refactor(config): remove global Quiet

* fix(db): take progress bar as an argument

* fix(progress): inject progress bar
2019-12-16 19:23:08 +02:00

41 lines
560 B
Go

package indicator
import (
"io"
"github.com/cheggaaa/pb/v3"
)
type ProgressBar struct {
quiet bool
}
func NewProgressBar(quiet bool) ProgressBar {
return ProgressBar{quiet: quiet}
}
func (p ProgressBar) Start(total int64) Bar {
if p.quiet {
return Bar{}
}
bar := pb.Full.Start64(total)
return Bar{bar: bar}
}
type Bar struct {
bar *pb.ProgressBar
}
func (b Bar) NewProxyReader(r io.Reader) io.Reader {
if b.bar == nil {
return r
}
return b.bar.NewProxyReader(r)
}
func (b Bar) Finish() {
if b.bar == nil {
return
}
b.bar.Finish()
}