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