Implement database profile and mode with cli flags
This commit is contained in:
parent
70f0b4d4f7
commit
132d0784b0
|
@ -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":
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storag
|
|||
StorageAreaId: storageAreaId,
|
||||
}
|
||||
|
||||
StoreCard(cardLocation)
|
||||
StoreCard(db, cardLocation)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue