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)
|
logic.Check(err)
|
||||||
|
|
||||||
//selectedStorageAreaName = name
|
//selectedStorageAreaName = name
|
||||||
|
// TODO: Make db call to cache StorageArea once we have the ID
|
||||||
cardLocation.StorageAreaId = id
|
cardLocation.StorageAreaId = id
|
||||||
break
|
break
|
||||||
case "c", "criteria":
|
case "c", "criteria":
|
||||||
|
@ -102,7 +103,7 @@ func MainCliLoop(db *sql.DB) {
|
||||||
cards, err := delverlens.ParseExportFile(filename)
|
cards, err := delverlens.ParseExportFile(filename)
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
|
|
||||||
err = logic.ImportDelverLensCards(cards)
|
err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId)
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
break
|
break
|
||||||
case "l", "locate":
|
case "l", "locate":
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DelverLensCard struct {
|
type DelverLensCard struct {
|
||||||
|
@ -38,10 +37,8 @@ func ParseExportFile(filename string) ([]DelverLensCard, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
card := DelverLensCard{
|
card := DelverLensCard{
|
||||||
Name: record[0],
|
ScryfallID: record[0],
|
||||||
IsFoil: record[1] == "Foil",
|
IsFoil: record[1] == "Foil",
|
||||||
CollectorNumber: record[2],
|
|
||||||
SetCode: strings.ToLower(record[3]),
|
|
||||||
}
|
}
|
||||||
cards = append(cards, card)
|
cards = append(cards, card)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storag
|
||||||
StorageAreaId: storageAreaId,
|
StorageAreaId: storageAreaId,
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreCard(cardLocation)
|
StoreCard(db, cardLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,44 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sevenkeys/cli"
|
"sevenkeys/cli"
|
||||||
"sevenkeys/database"
|
"sevenkeys/database"
|
||||||
"sevenkeys/figlet"
|
"sevenkeys/figlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ModeOfOperation string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ModeImport ModeOfOperation = "import"
|
||||||
|
ModeInteractive = "interactive"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var profile string
|
var profile string
|
||||||
if len(os.Args) < 2 {
|
flag.StringVar(&profile, "profile", "production", "the database profile to use")
|
||||||
profile = "production"
|
|
||||||
} else {
|
|
||||||
profile = os.Args[1]
|
|
||||||
}
|
|
||||||
db := database.GetDatabaseFromConfig("config." + profile + ".json")
|
|
||||||
|
|
||||||
|
modePtr := flag.String("mode", "interactive", "the mode of operation")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
mode := ModeOfOperation(*modePtr)
|
||||||
|
|
||||||
|
db := database.GetDatabaseFromConfig("config." + profile + ".json")
|
||||||
figlet.ReadFigletFonts()
|
figlet.ReadFigletFonts()
|
||||||
cli.ShowSplashScreen()
|
cli.ShowSplashScreen()
|
||||||
|
|
||||||
cli.RunUpdateCheck(db)
|
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