Skip to content

Commit f5f71b9

Browse files
committed
feat: progress bar for scanning files
1 parent 6930ecb commit f5f71b9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func main() {
6969

7070
// only scan local files if -f is provided
7171
if len(*requestedPath) > 0 {
72-
sockFound, err = runFiles(*requestedPath, w, *verbose)
72+
sockFound, err = runFiles(*requestedPath, w, *verbose, *progressBar)
7373
} else {
7474
// run against a live cluster
7575
sockFound, err = runCluster(*requestedNamespace, w, *verbose, *progressBar)
@@ -84,7 +84,7 @@ func main() {
8484
}
8585
}
8686

87-
func runFiles(requestedPath string, w *tabwriter.Writer, verbose int) (bool, error) {
87+
func runFiles(requestedPath string, w *tabwriter.Writer, verbose int, progressBar bool) (bool, error) {
8888
// run against local files
8989

9090
var files []string
@@ -113,7 +113,7 @@ func runFiles(requestedPath string, w *tabwriter.Writer, verbose int) (bool, err
113113
files = append(files, requestedPath)
114114
}
115115

116-
sockFound, err := printFiles(w, files, verbose)
116+
sockFound, err := printFiles(w, files, verbose, progressBar)
117117

118118
return sockFound, err
119119
}
@@ -397,10 +397,16 @@ func printVolumes(w *tabwriter.Writer, volumes []corev1.Volume, namespace, resTy
397397
return sockFound
398398
}
399399

400-
func printFiles(w *tabwriter.Writer, filePaths []string, verbose int) (bool, error) {
400+
func printFiles(w *tabwriter.Writer, filePaths []string, verbose int, progressBar bool) (bool, error) {
401401
// initialize sockFound to use for exit code
402402
sockFound := false
403403
// print output for scanning local manifest files
404+
numberFilePaths := len(filePaths)
405+
pbar := pb.New(numberFilePaths)
406+
if progressBar {
407+
fmt.Printf("Scanning %d files for docker.sock mounts", numberFilePaths)
408+
pbar.Start()
409+
}
404410
for _, file := range filePaths {
405411
mounted := "not-mounted"
406412
line, err := searchFile(file)
@@ -414,6 +420,12 @@ func printFiles(w *tabwriter.Writer, filePaths []string, verbose int) (bool, err
414420
if mounted == "mounted" || verbose > 3 {
415421
fmt.Fprintf(w, "%s\t%v\t%s\t\n", file, line, mounted)
416422
}
423+
if progressBar {
424+
pbar.Increment()
425+
}
426+
}
427+
if progressBar {
428+
pbar.Finish()
417429
}
418430
return sockFound, nil
419431
}

0 commit comments

Comments
 (0)