Skip to content

Commit bcf53b2

Browse files
committed
chore(cli/stores): Output number of creates and/or updates for import --csv
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent 02fb606 commit bcf53b2

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

cmd/storesBulkOperations.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,12 @@ If you do not wish to include credentials in your CSV file they can be provided
303303
}
304304

305305
log.Info().Msgf("Processing CSV rows from file '%s'", filePath)
306-
var inputHeader []string
306+
var (
307+
inputHeader []string
308+
totalUpdates int
309+
totalCreates int
310+
)
311+
307312
for idx, row := range inFile {
308313
log.Debug().Msgf("Processing row '%d'", idx)
309314
originalMap = append(originalMap, row)
@@ -359,9 +364,8 @@ If you do not wish to include credentials in your CSV file they can be provided
359364
Value: &storePassword,
360365
}
361366
}
362-
mJSON := stripAllBOMs(reqJson.String())
363367

364-
var createStoreReqParameters api.CreateStoreFctArgs
368+
mJSON := stripAllBOMs(reqJson.String())
365369
if storeId != "" && allowUpdates {
366370
updateReqParameters := api.UpdateStoreFctArgs{}
367371
conversionError := json.Unmarshal([]byte(mJSON), &updateReqParameters)
@@ -388,9 +392,11 @@ If you do not wish to include credentials in your CSV file they can be provided
388392
log.Info().Msgf("Successfully updated store from row '%d' as '%s'", idx, res.Id)
389393
resultsMap = append(resultsMap, []string{fmt.Sprintf("%s", res.Id)})
390394
inputMap[idx-1]["Id"] = res.Id
395+
totalUpdates++
391396
}
392397
continue
393398
}
399+
var createStoreReqParameters api.CreateStoreFctArgs
394400
conversionError := json.Unmarshal([]byte(mJSON), &createStoreReqParameters)
395401

396402
if conversionError != nil {
@@ -419,6 +425,7 @@ If you do not wish to include credentials in your CSV file they can be provided
419425
log.Info().Msgf("Successfully created store from row '%d' as '%s'", idx, res.Id)
420426
resultsMap = append(resultsMap, []string{fmt.Sprintf("%s", res.Id)})
421427
inputMap[idx-1]["Id"] = res.Id
428+
totalCreates++
422429
}
423430
}
424431

@@ -433,6 +440,7 @@ If you do not wish to include credentials in your CSV file they can be provided
433440
originalMap[oIdx] = extendedRow
434441
}
435442
totalRows := len(resultsMap)
443+
436444
totalSuccess := totalRows - errorCount
437445
log.Debug().Int("totalRows", totalRows).
438446
Int("totalSuccess", totalSuccess).Send()
@@ -448,7 +456,13 @@ If you do not wish to include credentials in your CSV file they can be provided
448456
outputResult(fmt.Sprintf("%d records processed.", totalRows), outputFormat)
449457
if totalSuccess > 0 {
450458
//fmt.Printf("\n%d certificate stores successfully created.", totalSuccess)
451-
outputResult(fmt.Sprintf("%d certificate stores successfully created.", totalSuccess), outputFormat)
459+
if totalCreates > 0 {
460+
outputResult(fmt.Sprintf("%d certificate stores successfully created.", totalCreates), outputFormat)
461+
}
462+
if totalUpdates > 0 {
463+
outputResult(fmt.Sprintf("%d certificate stores successfully updated.", totalUpdates), outputFormat)
464+
}
465+
452466
}
453467
if errorCount > 0 {
454468
//fmt.Printf("\n%d rows had errors.", errorCount)

0 commit comments

Comments
 (0)