@@ -40,6 +40,7 @@ import (
40
40
41
41
"github.com/bcmi-labs/arduino-cli/cmd/formatter"
42
42
"github.com/bcmi-labs/arduino-cli/cmd/pretty_print"
43
+ "github.com/bcmi-labs/arduino-cli/cmd/structs"
43
44
"github.com/bcmi-labs/arduino-cli/common"
44
45
"github.com/bcmi-labs/arduino-cli/libraries"
45
46
"github.com/bcmi-labs/arduino-cli/task"
@@ -118,42 +119,6 @@ var arduinoLibVersionCmd = &cobra.Command{
118
119
},
119
120
}
120
121
121
- //DownloadResult contains info about a completed Download process.
122
- type DownloadResult struct {
123
- Downloaded []string `json:"downloaded"`
124
- Errors map [string ]string `json:"errors"`
125
- }
126
-
127
- func (dr DownloadResult ) String () string {
128
- ret := ""
129
- for _ , name := range dr .Downloaded {
130
- ret += fmt .Sprintf ("%s - Downloaded\n " , name )
131
- }
132
- ret += "Errors:\n "
133
- for libName , err := range dr .Errors {
134
- ret += fmt .Sprintf ("%s - %s\n " , libName , err )
135
- }
136
- return ret
137
- }
138
-
139
- //InstallResult contains info about a completed installation process.
140
- type InstallResult struct {
141
- Installed []string `json:"installed"`
142
- Errors map [string ]string `json:"errors"`
143
- }
144
-
145
- func (dr InstallResult ) String () string {
146
- ret := ""
147
- for _ , name := range dr .Installed {
148
- ret += fmt .Sprintf ("%s - Installed\n " , name )
149
- }
150
- ret += "Errors:\n "
151
- for libName , err := range dr .Errors {
152
- ret += fmt .Sprintf ("%s - %s\n " , libName , err )
153
- }
154
- return ret
155
- }
156
-
157
122
func init () {
158
123
arduinoCmd .AddCommand (arduinoLibCmd )
159
124
arduinoLibCmd .AddCommand (arduinoLibInstallCmd )
@@ -195,20 +160,12 @@ func executeDownloadCommand(cmd *cobra.Command, args []string) error {
195
160
196
161
items , failed := extractValidLibraries (args , status )
197
162
198
- libraryOK , libraryFails := parallelLibDownloads (items , len ( args ) , true )
163
+ libraryResults := parallelLibDownloads (items , true )
199
164
for _ , fail := range failed {
200
- libraryFails [fail ] = "Not Found"
165
+ libraryResults [fail ] = "Error : Not Found"
201
166
}
202
167
203
- if GlobalFlags .Verbose > 0 {
204
- prettyPrints .DownloadLib (libraryOK , libraryFails )
205
- } else {
206
- formatter .Print (DownloadResult {
207
- Downloaded : libraryOK ,
208
- Errors : libraryFails ,
209
- })
210
-
211
- }
168
+ formatter .Print (structs .LibResultsFromMap (libraryResults ))
212
169
213
170
return nil
214
171
}
@@ -230,10 +187,9 @@ func extractValidLibraries(args []string, status *libraries.StatusContext) ([]*l
230
187
}
231
188
232
189
// parallelLibDownloads executes multiple libraries downloads in parallel
233
- func parallelLibDownloads (items []* libraries.Library , argC int , forced bool ) ([] string , map [string ]string ) {
190
+ func parallelLibDownloads (items []* libraries.Library , forced bool ) map [string ]string {
234
191
itemC := len (items )
235
- libraryOK := make ([]string , 0 , itemC )
236
- libraryFails := make (map [string ]string , argC - itemC )
192
+ libraryResults := make (map [string ]string , itemC )
237
193
238
194
tasks := make (map [string ]task.Wrapper , len (items ))
239
195
progressBars := make ([]* pb.ProgressBar , 0 , len (items ))
@@ -264,14 +220,14 @@ func parallelLibDownloads(items []*libraries.Library, argC int, forced bool) ([]
264
220
265
221
for libraryName , result := range results {
266
222
if result .Error != nil {
267
- libraryFails [libraryName ] = result . Error .Error ( )
223
+ libraryResults [libraryName ] = fmt . Sprintf ( " Error : %s" , result .Error )
268
224
} else {
269
- libraryOK = append ( libraryOK , libraryName )
225
+ libraryResults [ libraryName ] = "OK"
270
226
}
271
227
}
272
228
}
273
229
274
- return libraryOK , libraryFails
230
+ return libraryResults
275
231
}
276
232
277
233
func executeInstallCommand (cmd * cobra.Command , args []string ) error {
@@ -297,35 +253,22 @@ func executeInstallCommand(cmd *cobra.Command, args []string) error {
297
253
}
298
254
299
255
items , fails := extractValidLibraries (args , status )
300
- libraryOK := make ([]string , 0 , len (items ))
301
256
302
- _ , libraryFails := parallelLibDownloads (items , len ( args ) , false )
257
+ libraryResults := parallelLibDownloads (items , false )
303
258
for _ , fail := range fails {
304
- libraryFails [fail ] = "Not Found"
259
+ libraryResults [fail ] = "Not Found"
305
260
}
306
261
307
262
for _ , library := range items {
308
263
err = libraries .InstallLib (library , library .Latest ().Version )
309
264
if err != nil {
310
- libraryFails [library .Name ] = err . Error ( )
265
+ libraryResults [library .Name ] = fmt . Sprintf ( "Error : %s" , err )
311
266
} else {
312
- libraryOK = append ( libraryOK , library .Name )
267
+ libraryResults [ library .Name ] = "OK"
313
268
}
314
269
}
315
270
316
- if GlobalFlags .Verbose > 0 {
317
- prettyPrints .InstallLib (libraryOK , libraryFails )
318
- } else {
319
- okEnd := len (libraryOK )
320
- for i , library := range libraryOK {
321
- logrus .Infof ("%-10s - Installed (%d/%d)\n " , library , i + 1 , okEnd )
322
- }
323
- i := okEnd
324
- for library , failure := range libraryFails {
325
- i ++
326
- logrus .Infof ("%-10s - Error : %-10s (%d/%d)\n " , library , failure , i , len (libraryFails ))
327
- }
328
- }
271
+ formatter .Print (structs .LibResultsFromMap (libraryResults ))
329
272
330
273
return nil
331
274
}
0 commit comments