@@ -110,18 +110,33 @@ func UploadFiles(r *Request, api string, response map[string]interface{}, validF
110110 metadata , _ := params ["metadata" ].(string )
111111
112112 fmt .Println ("Uploading files for" , api , ":" , validFiles )
113- spinner := r .Config .StartSpinner (uploadingMessage )
113+
114+ var spinner * spinner.Spinner
115+ if r .Config .HasShell {
116+ spinner = r .Config .StartSpinner (uploadingMessage )
117+ }
118+
114119 errored := 0
115120 for i , filePath := range validFiles {
116- spinner .Suffix = fmt .Sprintf (" uploading %d/%d %s..." , i + 1 , len (validFiles ), filepath .Base (filePath ))
121+ if spinner != nil {
122+ spinner .Suffix = fmt .Sprintf (" uploading %d/%d %s..." , i + 1 , len (validFiles ), filepath .Base (filePath ))
123+ }
124+
117125 if err := uploadFile (i , len (validFiles ), postURL , filePath , signature , expires , metadata , spinner ); err != nil {
118- spinner .Stop ()
126+ if spinner != nil {
127+ spinner .Stop ()
128+ }
129+
119130 fmt .Println ("Error uploading" , filePath , ":" , err )
120131 errored ++
121- spinner .Suffix = fmt .Sprintf (" %s" , uploadingMessage )
122- spinner .Start ()
132+
133+ if spinner != nil {
134+ spinner .Suffix = fmt .Sprintf (" %s" , uploadingMessage )
135+ spinner .Start ()
136+ }
123137 }
124138 }
139+
125140 r .Config .StopSpinner (spinner )
126141 if errored > 0 {
127142 fmt .Printf ("🙈 %d out of %d files failed to upload.\n " , errored , len (validFiles ))
@@ -220,7 +235,9 @@ func uploadFile(index, count int, postURL, filePath, signature, expires, metadat
220235 f : tmp ,
221236 total : size ,
222237 update : func (pct int ) {
223- spn .Suffix = fmt .Sprintf (" [%d/%d] %s\t %s %d%%" , index + 1 , count , fileName , barArrow (pct ), pct )
238+ if spn != nil {
239+ spn .Suffix = fmt .Sprintf (" [%d/%d] %s\t %s %d%%" , index + 1 , count , fileName , barArrow (pct ), pct )
240+ }
224241 },
225242 }
226243 req .Body = pb
@@ -247,9 +264,13 @@ func uploadFile(index, count int, postURL, filePath, signature, expires, metadat
247264 return fmt .Errorf ("[%d/%d] %s\t upload failed: %s" , index + 1 , count , fileName , string (b ))
248265 }
249266
250- spn .Stop ()
267+ if spn != nil {
268+ spn .Stop ()
269+ }
251270 fmt .Printf ("[%d/%d] %s\t %s ✅\n " , index + 1 , count , fileName , barArrow (100 ))
252- spn .Suffix = fmt .Sprintf (" %s" , uploadingMessage )
253- spn .Start ()
271+ if spn != nil {
272+ spn .Suffix = fmt .Sprintf (" %s" , uploadingMessage )
273+ spn .Start ()
274+ }
254275 return nil
255276}
0 commit comments