feat: add repeat flag to automatically repeat sync process

main
RaviAnand Mohabir 1 year ago
parent eddca837e6
commit d4a7a5cafd

@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"time"
"gitea.ravianand.me/Dan6erbond/listy/core"
"gitea.ravianand.me/Dan6erbond/listy/lists"
@ -35,17 +36,29 @@ to quickly create a Cobra application.`,
panic(err)
}
for _, user := range users {
numAdded, err := lists.SyncMonthlyList(ctx, app, user)
repeat, err := cmd.Flags().GetDuration("repeat")
if err != nil {
log.Println(err)
}
if err != nil {
panic(err)
}
for range time.Tick(repeat) {
for _, user := range users {
numAdded, err := lists.SyncMonthlyList(ctx, app, user)
if err != nil {
log.Println(err)
}
if numAdded == 0 {
fmt.Printf("No new songs for %s", user.SpotifyID)
} else {
fmt.Printf("Added %d songs for %s", numAdded, user.SpotifyID)
}
if numAdded == 0 {
fmt.Printf("No new songs for %s", user.SpotifyID)
} else {
fmt.Printf("Added %d songs for %s", numAdded, user.SpotifyID)
if repeat == time.Duration(0) {
break
}
}
}
},
@ -62,5 +75,5 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// syncCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
syncCmd.Flags().DurationP("repeat", "r", 0, "Repeat duration for sync process")
}

Loading…
Cancel
Save