Files
trivy/pkg/indicator/progress.go
rahul2393 793a1aa3c8 Add linter check support (#679)
* add linter supports

* add only minor version

* use latest version

* Fix println with format issue

* Fix test

* Fix tests

* For slice with unknown length, preallocating the array

* fix code-coverage

* Removed linter rules

* Reverting linter fixes, adding TODO for later

* Ignore linter error for import

* Remove another err var.

* Ignore shadow error

* Fixes

* Fix issue

* Add back goimports local-prefixes

* Update local prefixes

* Removed extra spaces and merge the imports

* more refactoring

* Update photon.go

Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
2020-10-20 15:20:04 +03:00

48 lines
864 B
Go

package indicator
import (
"io"
"github.com/cheggaaa/pb/v3"
)
// ProgressBar exports method to track the progress of jobs
type ProgressBar struct {
quiet bool
}
// NewProgressBar is the factory method to return progressBar object
func NewProgressBar(quiet bool) ProgressBar {
return ProgressBar{quiet: quiet}
}
// Start starts the progress tracking
func (p ProgressBar) Start(total int64) Bar {
if p.quiet {
return Bar{}
}
bar := pb.Full.Start64(total)
return Bar{bar: bar}
}
// Bar is the proxy progress bar
type Bar struct {
bar *pb.ProgressBar
}
// NewProxyReader is the factory method to track the progress
func (b Bar) NewProxyReader(r io.Reader) io.Reader {
if b.bar == nil {
return r
}
return b.bar.NewProxyReader(r)
}
// Finish finishes the progress tracking
func (b Bar) Finish() {
if b.bar == nil {
return
}
b.bar.Finish()
}