Ask user if update should be performed

This commit is contained in:
The Magician 2024-05-28 15:38:30 +01:00
parent 8b7ec980f4
commit 708bfdf90b
2 changed files with 17 additions and 5 deletions

View File

@ -2,8 +2,10 @@ package logic
import (
"database/sql"
"fmt"
"sevenkeys/database"
"sevenkeys/logic/scryfall"
"strings"
"time"
)
@ -30,3 +32,11 @@ func CheckForUpdates(db *sql.DB) (bool, error) {
return bulkCardsUpdatedTimestamp.After(cachedFileTimestamp), nil
}
func ConfirmUpdate() bool {
fmt.Print("Run update? (y/N) ")
var response string
fmt.Scan(&response)
return strings.ToUpper(response) == "Y"
}

View File

@ -9,16 +9,18 @@ import (
func main() {
db := database.GetDatabaseFromConfig("config.json")
fmt.Println("Checking for updates...")
needsUpdate, err := logic.CheckForUpdates(db)
logic.Check(err)
if needsUpdate {
fmt.Println("Needs update")
fmt.Println("Update required.")
if logic.ConfirmUpdate() {
fmt.Println("User authorized update")
/*
if logic.AskForScryfallUpdate() {
err = logic.RunScryfallUpdate()
logic.Check(err)
}
*/
}
}
}