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 ( import (
"database/sql" "database/sql"
"fmt"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/logic/scryfall" "sevenkeys/logic/scryfall"
"strings"
"time" "time"
) )
@ -30,3 +32,11 @@ func CheckForUpdates(db *sql.DB) (bool, error) {
return bulkCardsUpdatedTimestamp.After(cachedFileTimestamp), nil 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() { func main() {
db := database.GetDatabaseFromConfig("config.json") db := database.GetDatabaseFromConfig("config.json")
fmt.Println("Checking for updates...")
needsUpdate, err := logic.CheckForUpdates(db) needsUpdate, err := logic.CheckForUpdates(db)
logic.Check(err) logic.Check(err)
if needsUpdate { if needsUpdate {
fmt.Println("Needs update") fmt.Println("Update required.")
/* if logic.ConfirmUpdate() {
if logic.AskForScryfallUpdate() { fmt.Println("User authorized update")
/*
err = logic.RunScryfallUpdate() err = logic.RunScryfallUpdate()
logic.Check(err) logic.Check(err)
} */
*/ }
} }
} }