From 132d0784b072f713b4115c048d821e66bd37fdba Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 25 Sep 2024 11:48:01 +0100 Subject: [PATCH] Implement database profile and mode with cli flags --- sevenkeys/cli/mainui.go | 3 ++- sevenkeys/delverlens/delverlens.go | 7 ++---- sevenkeys/logic/import.go | 4 +++- sevenkeys/main.go | 35 +++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/sevenkeys/cli/mainui.go b/sevenkeys/cli/mainui.go index cd49829..3a97e88 100644 --- a/sevenkeys/cli/mainui.go +++ b/sevenkeys/cli/mainui.go @@ -64,6 +64,7 @@ func MainCliLoop(db *sql.DB) { logic.Check(err) //selectedStorageAreaName = name + // TODO: Make db call to cache StorageArea once we have the ID cardLocation.StorageAreaId = id break case "c", "criteria": @@ -102,7 +103,7 @@ func MainCliLoop(db *sql.DB) { cards, err := delverlens.ParseExportFile(filename) logic.Check(err) - err = logic.ImportDelverLensCards(cards) + err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId) logic.Check(err) break case "l", "locate": diff --git a/sevenkeys/delverlens/delverlens.go b/sevenkeys/delverlens/delverlens.go index 84616d6..491c39d 100644 --- a/sevenkeys/delverlens/delverlens.go +++ b/sevenkeys/delverlens/delverlens.go @@ -4,7 +4,6 @@ import ( "encoding/csv" "io" "os" - "strings" ) type DelverLensCard struct { @@ -38,10 +37,8 @@ func ParseExportFile(filename string) ([]DelverLensCard, error) { } card := DelverLensCard{ - Name: record[0], - IsFoil: record[1] == "Foil", - CollectorNumber: record[2], - SetCode: strings.ToLower(record[3]), + ScryfallID: record[0], + IsFoil: record[1] == "Foil", } cards = append(cards, card) } diff --git a/sevenkeys/logic/import.go b/sevenkeys/logic/import.go index 146e67c..351c3f5 100644 --- a/sevenkeys/logic/import.go +++ b/sevenkeys/logic/import.go @@ -20,6 +20,8 @@ func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storag StorageAreaId: storageAreaId, } - StoreCard(cardLocation) + StoreCard(db, cardLocation) } + + return nil } diff --git a/sevenkeys/main.go b/sevenkeys/main.go index 30091bc..a4e3310 100644 --- a/sevenkeys/main.go +++ b/sevenkeys/main.go @@ -1,25 +1,44 @@ package main import ( + "flag" + "fmt" "os" "sevenkeys/cli" "sevenkeys/database" "sevenkeys/figlet" ) +type ModeOfOperation string + +const ( + ModeImport ModeOfOperation = "import" + ModeInteractive = "interactive" +) + func main() { var profile string - if len(os.Args) < 2 { - profile = "production" - } else { - profile = os.Args[1] - } - db := database.GetDatabaseFromConfig("config." + profile + ".json") + flag.StringVar(&profile, "profile", "production", "the database profile to use") + modePtr := flag.String("mode", "interactive", "the mode of operation") + + flag.Parse() + mode := ModeOfOperation(*modePtr) + + db := database.GetDatabaseFromConfig("config." + profile + ".json") figlet.ReadFigletFonts() cli.ShowSplashScreen() - cli.RunUpdateCheck(db) - cli.MainCliLoop(db) + switch mode { + case ModeImport: + // TODO: Get filename, run import code + break + case ModeInteractive: + cli.MainCliLoop(db) + break + default: + fmt.Fprintf(os.Stderr, "Unrecognized mode: %s\n", mode) + break + } }