Minor refactor and print records deleted

This commit is contained in:
Balakrishnan Balasubramanian 2023-03-24 09:06:54 -04:00
parent 12636615fa
commit 0de7f06195

23
main.go
View File

@ -79,25 +79,10 @@ func selectRecordsToDelete(recs []libdns.Record) []libdns.Record {
case delRange == "none": case delRange == "none":
return nil return nil
default: default:
indexGen := func() func() int {
indexes := parseRange(delRange, len(recs)-1) indexes := parseRange(delRange, len(recs)-1)
indexIndex := 0
return func() int {
if indexIndex == len(indexes) {
return -1
}
val := indexes[indexIndex]
indexIndex++
return val
}
}()
return func() (result []libdns.Record) { return func() (result []libdns.Record) {
nextIndex := indexGen() for _, index := range indexes {
for i, r := range recs { result = append(result, recs[index])
if i == nextIndex {
result = append(result, r)
nextIndex = indexGen()
}
} }
return return
}() }()
@ -127,11 +112,11 @@ func main() {
log.Panicln(err) log.Panicln(err)
} }
recs = selectRecordsToDelete(recs) recs = selectRecordsToDelete(recs)
recs, err = provider.DeleteRecords(ctx, zone, recs) deletedRecords, err := provider.DeleteRecords(ctx, zone, recs)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }
if len(recs) == 0 { if len(deletedRecords) == 0 {
fmt.Println("Nothing was deleted") fmt.Println("Nothing was deleted")
} else { } else {
fmt.Println("Records deleted:") fmt.Println("Records deleted:")