111 lines
2.5 KiB
Go
111 lines
2.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"sevenkeys/database"
|
|
"sevenkeys/logic"
|
|
)
|
|
|
|
var output string
|
|
|
|
func MainCliLoop(db *sql.DB) {
|
|
var command string
|
|
|
|
var selectedStorageArea database.StorageArea
|
|
var cardLocation database.CardLocation
|
|
|
|
var insertSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
|
|
SetCode: "",
|
|
Foil: logic.Either,
|
|
Promo: logic.Either,
|
|
Language: "en",
|
|
}
|
|
var insertSearchOptions logic.InsertSearchOptions
|
|
|
|
// TODO: Make these do something and add the ability to modify them
|
|
var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
|
|
SetCode: "",
|
|
Foil: logic.True,
|
|
Promo: logic.Either,
|
|
Language: "en",
|
|
}
|
|
|
|
for {
|
|
ShowSplashScreen()
|
|
showStorageInfo(os.Stdout, selectedStorageArea)
|
|
showInsertSearchCriteria(insertSearchCriteria)
|
|
showSelectedCard()
|
|
showCopiesInserted()
|
|
|
|
command = GetStringResponse("SEVENKEYS $")
|
|
|
|
var err error
|
|
|
|
switch command {
|
|
case "q", "quit":
|
|
return
|
|
case "n", "newstorage":
|
|
var storageArea database.StorageArea
|
|
storageArea.Name = GetStringResponse("Storage area name:")
|
|
storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):")
|
|
err = logic.CreateStorageArea(db, storageArea)
|
|
logic.Check(err)
|
|
break
|
|
case "a", "area":
|
|
area, err := logic.SelectStorageArea(db)
|
|
logic.Check(err)
|
|
selectedStorageArea = area
|
|
cardLocation.StorageAreaId = area.Id
|
|
break
|
|
case "c", "criteria":
|
|
insertSearchCriteria = getSearchCriteria()
|
|
break
|
|
case "s", "search":
|
|
if shouldRefreshSearch {
|
|
insertSearchOptions = getSearchOptions(db, insertSearchCriteria)
|
|
}
|
|
|
|
var previousCardPrintingId = cardLocation.CardPrintingId
|
|
|
|
pk, err := logic.GenericSearch(insertSearchOptions)
|
|
cardLocation.CardPrintingId = pk
|
|
|
|
var exitError *exec.ExitError
|
|
if errors.As(err, &exitError) {
|
|
break
|
|
}
|
|
logic.Check(err)
|
|
|
|
output = ""
|
|
if cardLocation.CardPrintingId != previousCardPrintingId {
|
|
copiesInserted = 0
|
|
}
|
|
break
|
|
case "i", "insert":
|
|
insertSelectedCard(db, selectedStorageArea, cardLocation)
|
|
break
|
|
case "l", "locate":
|
|
filename := GetStringResponse("Filename:")
|
|
cardNames, err := logic.GetCardNamesFromFile(filename)
|
|
logic.Check(err)
|
|
|
|
locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria)
|
|
logic.Check(err)
|
|
|
|
for _, location := range locations {
|
|
fmt.Println(location)
|
|
}
|
|
fmt.Scanln()
|
|
|
|
break
|
|
default:
|
|
fmt.Println("Unrecognized command:", command)
|
|
break
|
|
}
|
|
}
|
|
}
|