@@ -127,8 +127,11 @@ type HubDownloadOptions struct {
127127 PluginName string
128128 PluginVersion string
129129}
130+ type DownloaderOptions struct {
131+ NoProgress bool
132+ }
130133
131- func DownloadPluginFromHub (ctx context.Context , c * cloudquery_api.ClientWithResponses , ops HubDownloadOptions ) error {
134+ func DownloadPluginFromHub (ctx context.Context , c * cloudquery_api.ClientWithResponses , ops HubDownloadOptions , dops DownloaderOptions ) error {
132135 downloadDir := filepath .Dir (ops .LocalPath )
133136 if _ , err := os .Stat (ops .LocalPath ); err == nil {
134137 return nil
@@ -162,7 +165,7 @@ func DownloadPluginFromHub(ctx context.Context, c *cloudquery_api.ClientWithResp
162165 return fmt .Errorf ("failed to get plugin metadata from hub: empty location from response" )
163166 }
164167 pluginZipPath := ops .LocalPath + ".zip"
165- writtenChecksum , err := downloadFile (ctx , pluginZipPath , location )
168+ writtenChecksum , err := downloadFile (ctx , pluginZipPath , location , dops )
166169 if err != nil {
167170 return fmt .Errorf ("failed to download plugin: %w" , err )
168171 }
@@ -236,7 +239,7 @@ func downloadPluginAssetFromHub(ctx context.Context, c *cloudquery_api.ClientWit
236239 }
237240}
238241
239- func DownloadPluginFromGithub (ctx context.Context , logger zerolog.Logger , localPath string , org string , name string , version string , typ PluginType ) error {
242+ func DownloadPluginFromGithub (ctx context.Context , logger zerolog.Logger , localPath string , org string , name string , version string , typ PluginType , dops DownloaderOptions ) error {
240243 downloadDir := filepath .Dir (localPath )
241244 pluginZipPath := localPath + ".zip"
242245
@@ -253,7 +256,7 @@ func DownloadPluginFromGithub(ctx context.Context, logger zerolog.Logger, localP
253256 return fmt .Errorf ("failed to get plugin url: %w" , err )
254257 }
255258 logger .Debug ().Msg (fmt .Sprintf ("Downloading %s" , downloadURL ))
256- if _ , err := downloadFile (ctx , pluginZipPath , downloadURL ); err != nil {
259+ if _ , err := downloadFile (ctx , pluginZipPath , downloadURL , dops ); err != nil {
257260 return fmt .Errorf ("failed to download plugin: %w" , err )
258261 }
259262
@@ -301,20 +304,16 @@ func DownloadPluginFromGithub(ctx context.Context, logger zerolog.Logger, localP
301304 return nil
302305}
303306
304- func downloadFile (ctx context.Context , localPath string , downloadURL string ) (string , error ) {
307+ func downloadFile (ctx context.Context , localPath string , downloadURL string , dops DownloaderOptions ) (string , error ) {
305308 // Create the file
306309 out , err := os .Create (localPath )
307310 if err != nil {
308311 return "" , fmt .Errorf ("failed to create file %s: %w" , localPath , err )
309312 }
310313 defer out .Close ()
311314
312- return downloadFileFromURL (ctx , out , downloadURL )
313- }
314-
315- func downloadFileFromURL (ctx context.Context , out * os.File , downloadURL string ) (string , error ) {
316315 checksum := ""
317- err : = retry .Do (func () error {
316+ err = retry .Do (func () error {
318317 checksum = ""
319318 // Get the data
320319 req , err := http .NewRequestWithContext (ctx , http .MethodGet , downloadURL , nil )
@@ -344,11 +343,17 @@ func downloadFileFromURL(ctx context.Context, out *os.File, downloadURL string)
344343 urlForLog = parsedURL .String ()
345344 }
346345 fmt .Printf ("Downloading %s\n " , urlForLog )
347- bar := downloadProgressBar (resp .ContentLength , "Downloading" )
348346
349347 s := sha256 .New ()
350- // Writer the body to file
351- _ , err = io .Copy (io .MultiWriter (out , bar , s ), resp .Body )
348+ writers := []io.Writer {out , s }
349+
350+ if ! dops .NoProgress {
351+ bar := downloadProgressBar (resp .ContentLength , "Downloading" )
352+ writers = append (writers , bar )
353+ }
354+
355+ // Write the body to file
356+ _ , err = io .Copy (io .MultiWriter (writers ... ), resp .Body )
352357 if err != nil {
353358 return fmt .Errorf ("failed to copy body to file %s: %w" , out .Name (), err )
354359 }
0 commit comments