mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 15:37:50 -08:00
Support --quiet option
This commit is contained in:
@@ -73,6 +73,10 @@ OPTIONS:
|
||||
Name: "clean, c",
|
||||
Usage: "clean all cache",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "quiet, q",
|
||||
Usage: "suppress progress bar",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug, d",
|
||||
Usage: "debug mode",
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/knqyf263/trivy/pkg/log"
|
||||
"github.com/knqyf263/trivy/pkg/utils"
|
||||
"golang.org/x/xerrors"
|
||||
@@ -38,8 +36,8 @@ func CloneOrPull(url, repoPath string) (map[string]struct{}, error) {
|
||||
}
|
||||
log.Logger.Debug("remove an existed directory")
|
||||
|
||||
s := spinner.New(spinner.CharSets[36], 100*time.Millisecond)
|
||||
s.Suffix = " The first time will take a while..."
|
||||
suffix := " The first time will take a while..."
|
||||
s := utils.NewSpinner(suffix)
|
||||
s.Start()
|
||||
defer s.Stop()
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ func Run(c *cli.Context) (err error) {
|
||||
cli.ShowAppHelpAndExit(c, 1)
|
||||
}
|
||||
|
||||
utils.Quiet = c.Bool("quiet")
|
||||
|
||||
clean := c.Bool("clean")
|
||||
if clean {
|
||||
log.Logger.Info("Cleaning caches...")
|
||||
|
||||
63
pkg/utils/progress.go
Normal file
63
pkg/utils/progress.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
pb "gopkg.in/cheggaaa/pb.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
Quiet = false
|
||||
)
|
||||
|
||||
type Spinner struct {
|
||||
client *spinner.Spinner
|
||||
}
|
||||
|
||||
func NewSpinner(suffix string) *Spinner {
|
||||
if Quiet {
|
||||
return &Spinner{}
|
||||
}
|
||||
s := spinner.New(spinner.CharSets[36], 100*time.Millisecond)
|
||||
s.Suffix = suffix
|
||||
return &Spinner{client: s}
|
||||
}
|
||||
|
||||
func (s *Spinner) Start() {
|
||||
if s.client == nil {
|
||||
return
|
||||
}
|
||||
s.client.Start()
|
||||
}
|
||||
func (s *Spinner) Stop() {
|
||||
if s.client == nil {
|
||||
return
|
||||
}
|
||||
s.client.Stop()
|
||||
}
|
||||
|
||||
type ProgressBar struct {
|
||||
client *pb.ProgressBar
|
||||
}
|
||||
|
||||
func PbStartNew(total int) *ProgressBar {
|
||||
if Quiet {
|
||||
return &ProgressBar{}
|
||||
}
|
||||
bar := pb.StartNew(total)
|
||||
return &ProgressBar{client: bar}
|
||||
}
|
||||
|
||||
func (p *ProgressBar) Increment() {
|
||||
if p.client == nil {
|
||||
return
|
||||
}
|
||||
p.client.Increment()
|
||||
}
|
||||
func (p *ProgressBar) Finish() {
|
||||
if p.client == nil {
|
||||
return
|
||||
}
|
||||
p.client.Finish()
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package alpine
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
@@ -37,7 +36,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("Alpine updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
|
||||
var cves []AlpineCVE
|
||||
|
||||
@@ -3,7 +3,6 @@ package debianoval
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -39,7 +38,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("Debian OVAL updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
|
||||
var cves []DebianOVAL
|
||||
|
||||
@@ -3,7 +3,6 @@ package debian
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -45,7 +44,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("Debian updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
|
||||
var cves []DebianCVE
|
||||
|
||||
@@ -2,7 +2,6 @@ package nvd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
@@ -35,7 +34,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("NVD updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
var items []vulnerability.Item
|
||||
err = utils.FileWalk(rootDir, targets, func(r io.Reader, _ string) error {
|
||||
|
||||
@@ -3,7 +3,6 @@ package redhat
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
@@ -41,7 +40,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("Red Hat updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
|
||||
var cves []RedhatCVE
|
||||
|
||||
@@ -3,7 +3,6 @@ package ubuntu
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
@@ -56,7 +55,7 @@ func Update(dir string, updatedFiles map[string]struct{}) error {
|
||||
}
|
||||
log.Logger.Debugf("Ubuntu OVAL updated files: %d", len(targets))
|
||||
|
||||
bar := pb.StartNew(len(targets))
|
||||
bar := utils.PbStartNew(len(targets))
|
||||
defer bar.Finish()
|
||||
|
||||
var cves []UbuntuCVE
|
||||
|
||||
Reference in New Issue
Block a user