@@ -90,12 +90,7 @@ func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutine
9090 inventory := scanner .NewInventory (a .Opa , pkgsupplyClient , provider , providerVersion )
9191
9292 log .Debug ().Msgf ("Starting repository analysis for organization: %s on %s" , org , provider )
93- bar := progressbar .NewOptions (
94- 0 ,
95- progressbar .OptionSetDescription ("Analyzing repositories" ),
96- progressbar .OptionShowCount (),
97- progressbar .OptionSetWriter (os .Stderr ),
98- )
93+ bar := a .progressBar (0 , "Analyzing repositories" )
9994
10095 var wg sync.WaitGroup
10196 errChan := make (chan error , 1 )
@@ -162,6 +157,8 @@ func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutine
162157 }
163158 }
164159
160+ _ = bar .Finish ()
161+
165162 return a .finalizeAnalysis (ctx , inventory )
166163}
167164
@@ -187,19 +184,18 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
187184 inventory := scanner .NewInventory (a .Opa , pkgsupplyClient , provider , providerVersion )
188185
189186 log .Debug ().Msgf ("Starting repository analysis for: %s/%s on %s" , org , repoName , provider )
190- bar := progressbar .NewOptions (
191- 1 ,
192- progressbar .OptionSetDescription ("Analyzing repository" ),
193- progressbar .OptionShowCount (),
194- progressbar .OptionSetWriter (os .Stderr ),
195- )
187+ bar := a .progressBar (2 , "Cloning repository" )
188+ _ = bar .RenderBlank ()
196189
197190 tempDir , err := a .cloneRepoToTemp (ctx , repo .BuildGitURL (a .ScmClient .GetProviderBaseURL ()), a .ScmClient .GetToken (), ref )
198191 if err != nil {
199192 return err
200193 }
201194 defer os .RemoveAll (tempDir )
202195
196+ bar .Describe ("Analyzing repository" )
197+ _ = bar .Add (1 )
198+
203199 pkg , err := a .generatePackageInsights (ctx , tempDir , repo , ref )
204200 if err != nil {
205201 return err
@@ -209,9 +205,8 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
209205 if err != nil {
210206 return err
211207 }
212- _ = bar .Add ( 1 )
208+ _ = bar .Finish ( )
213209
214- fmt .Print ("\n \n " )
215210 return a .finalizeAnalysis (ctx , inventory )
216211}
217212
@@ -237,12 +232,6 @@ func (a *Analyzer) AnalyzeLocalRepo(ctx context.Context, repoPath string) error
237232 inventory := scanner .NewInventory (a .Opa , pkgsupplyClient , provider , providerVersion )
238233
239234 log .Debug ().Msgf ("Starting repository analysis for: %s/%s on %s" , org , repoName , provider )
240- bar := progressbar .NewOptions (
241- 1 ,
242- progressbar .OptionSetDescription ("Analyzing repository" ),
243- progressbar .OptionShowCount (),
244- progressbar .OptionSetWriter (os .Stderr ),
245- )
246235
247236 pkg , err := a .generatePackageInsights (ctx , repoPath , repo , "" )
248237 if err != nil {
@@ -253,9 +242,7 @@ func (a *Analyzer) AnalyzeLocalRepo(ctx context.Context, repoPath string) error
253242 if err != nil {
254243 return err
255244 }
256- _ = bar .Add (1 )
257245
258- fmt .Print ("\n \n " )
259246 return a .finalizeAnalysis (ctx , inventory )
260247}
261248
@@ -325,3 +312,18 @@ func (a *Analyzer) cloneRepoToTemp(ctx context.Context, gitURL string, token str
325312 }
326313 return tempDir , nil
327314}
315+
316+ func (a * Analyzer ) progressBar (max int64 , description string ) * progressbar.ProgressBar {
317+ if a .Config .Quiet {
318+ return progressbar .DefaultSilent (max , description )
319+ } else {
320+ return progressbar .NewOptions64 (
321+ max ,
322+ progressbar .OptionSetDescription (description ),
323+ progressbar .OptionShowCount (),
324+ progressbar .OptionSetWriter (os .Stderr ),
325+ progressbar .OptionClearOnFinish (),
326+ )
327+
328+ }
329+ }
0 commit comments