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":
return nil
default:
indexGen := func() func() int {
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) {
nextIndex := indexGen()
for i, r := range recs {
if i == nextIndex {
result = append(result, r)
nextIndex = indexGen()
}
for _, index := range indexes {
result = append(result, recs[index])
}
return
}()
@ -127,11 +112,11 @@ func main() {
log.Panicln(err)
}
recs = selectRecordsToDelete(recs)
recs, err = provider.DeleteRecords(ctx, zone, recs)
deletedRecords, err := provider.DeleteRecords(ctx, zone, recs)
if err != nil {
log.Panicln(err)
}
if len(recs) == 0 {
if len(deletedRecords) == 0 {
fmt.Println("Nothing was deleted")
} else {
fmt.Println("Records deleted:")