@@ -40,6 +40,7 @@ func main() {
4040 // flags
4141 requestedNamespace := pflag .StringP ("namespace" , "n" , "ALL" , "Namespace to search for pods" )
4242 requestedPath := pflag .StringP ("filename" , "f" , "" , "File or directory to scan" )
43+ progressBar := pflag .BoolP ("progress" , "p" , false , "Show a progress bar when scanning" )
4344 help := pflag .BoolP ("help" , "h" , false , "Print usage" )
4445 exitErr := pflag .BoolP ("exit-with-error" , "e" , false , "Exit with error code if docker.sock found" )
4546 verbose := pflag .IntP ("verbose" , "v" , 2 , "Logging level" )
@@ -71,7 +72,7 @@ func main() {
7172 sockFound , err = runFiles (* requestedPath , w , * verbose )
7273 } else {
7374 // run against a live cluster
74- sockFound , err = runCluster (* requestedNamespace , w , * verbose )
75+ sockFound , err = runCluster (* requestedNamespace , w , * verbose , * progressBar )
7576 }
7677 if err != nil {
7778 fmt .Fprintf (os .Stderr , "error: %v" , err )
@@ -117,7 +118,7 @@ func runFiles(requestedPath string, w *tabwriter.Writer, verbose int) (bool, err
117118 return sockFound , err
118119}
119120
120- func runCluster (requestedNamespace string , w * tabwriter.Writer , verbose int ) (bool , error ) {
121+ func runCluster (requestedNamespace string , w * tabwriter.Writer , verbose int , progressBar bool ) (bool , error ) {
121122
122123 var sockFound bool
123124 // append true or false for each namespace to report accurate value if docker.sock is found
@@ -149,19 +150,26 @@ func runCluster(requestedNamespace string, w *tabwriter.Writer, verbose int) (bo
149150 }
150151
151152 namespaceErrors := make ([]error , 0 )
152- // loop through each namespace
153153 numberNamespaces := len (namespaceList .Items )
154- fmt .Printf ("scanning %d namespaces: \n " , numberNamespaces )
155- pbar := pb .StartNew (numberNamespaces )
154+ pbar := pb .New (numberNamespaces )
155+ // loop through each namespace
156+ if progressBar {
157+ fmt .Printf ("scanning %d namespaces: \n " , numberNamespaces )
158+ pbar .Start ()
159+ }
156160 for _ , namespace := range namespaceList .Items {
157161 sockFound , err := printResources (namespace , clientset , w , verbose )
158162 if err != nil {
159163 namespaceErrors = append (namespaceErrors , err )
160164 }
161165 sockFoundNamespaces = append (sockFoundNamespaces , sockFound )
162- pbar .Increment ()
166+ if progressBar {
167+ pbar .Increment ()
168+ }
169+ }
170+ if progressBar {
171+ pbar .Finish ()
163172 }
164- pbar .Finish ()
165173 if len (namespaceErrors ) > 0 {
166174 return sockFound , utilerrors .NewAggregate (namespaceErrors )
167175 }
0 commit comments