TheMathemagicians/sevenkeys/cli/mainui.go

159 lines
3.6 KiB
Go
Raw Normal View History

2024-06-10 15:34:16 +00:00
package cli
import (
2024-06-11 09:43:30 +00:00
"database/sql"
2024-06-10 15:34:16 +00:00
"fmt"
2024-08-20 11:57:36 +00:00
"sevenkeys/database"
2024-06-12 20:33:50 +00:00
"sevenkeys/logic"
2024-06-10 15:34:16 +00:00
)
var output string
2024-06-11 09:57:02 +00:00
func MainCliLoop(db *sql.DB) {
2024-06-10 15:34:16 +00:00
var command string
//var selectedStorageAreaName string
var cardLocation database.CardLocation
2024-06-10 15:34:16 +00:00
var insertSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "en",
}
//var insertSearchOptions logic.InsertSearchOptions
2024-09-13 11:32:18 +00:00
// TODO: Add the ability to modify this
/*
var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.True,
Promo: logic.Either,
Language: "en",
}
*/
2024-09-07 23:24:24 +00:00
2024-06-10 15:34:16 +00:00
for {
2024-06-12 20:33:50 +00:00
ShowSplashScreen()
// TODO: Fix this
//showStorageInfo(os.Stdout, selectedStorageAreaName)
showInsertSearchCriteria(insertSearchCriteria)
showSelectedCard()
showCopiesInserted()
2024-06-12 20:33:50 +00:00
2024-06-10 15:34:16 +00:00
command = GetStringResponse("SEVENKEYS $")
//var err error
2024-08-20 11:57:36 +00:00
2024-06-10 15:34:16 +00:00
switch command {
2024-10-04 20:51:05 +00:00
/*
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":
options, err := logic.GetStorageAreaSearchOptions(db)
logic.Check(err)
id, _, err := logic.GenericSearch(options)
logic.Check(err)
//selectedStorageAreaName = name
// TODO: Make db call to cache StorageArea once we have the ID
cardLocation.StorageAreaId = id
break
case "c", "criteria":
insertSearchCriteria = getSearchCriteria()
break
case "s", "search":
if shouldRefreshSearch {
insertSearchOptions = getSearchOptions(db, insertSearchCriteria)
}
2024-09-17 10:25:51 +00:00
2024-10-04 20:51:05 +00:00
var previousCardPrintingId = cardLocation.CardPrintingId
2024-09-17 10:25:51 +00:00
2024-10-04 20:51:05 +00:00
pk, searchLine, err := logic.GenericSearch(insertSearchOptions)
cardLocation.CardPrintingId = pk
selectedCardPrintingSearchLine = searchLine
2024-10-04 20:51:05 +00:00
var exitError *exec.ExitError
if errors.As(err, &exitError) {
break
}
logic.Check(err)
2024-10-04 20:51:05 +00:00
output = ""
if cardLocation.CardPrintingId != previousCardPrintingId {
copiesInserted = 0
}
2024-06-12 20:33:50 +00:00
break
2024-10-04 20:51:05 +00:00
*/
case "i", "insert":
_, err := logic.StoreCard(db, cardLocation)
2024-09-17 10:25:51 +00:00
logic.Check(err)
copiesInserted++
break
2024-10-04 20:51:05 +00:00
/*
case "d", "delverlens":
filename := GetStringResponse("Filename:")
cards, err := delverlens.ParseExportFile(filename)
logic.Check(err)
err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId)
logic.Check(err)
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)
if len(locations) == 0 {
fmt.Println("No results found")
fmt.Scanln()
2024-09-13 19:05:28 +00:00
break
2024-09-13 11:32:18 +00:00
}
2024-10-04 20:51:05 +00:00
for _, location := range locations {
description := logic.GetLocationDescription(location)
fmt.Println(description)
for true {
todo := GetStringResponse("TODO:")
if todo == "r" {
logic.RemoveFromStorage(db, location)
break
} else if todo == "n" {
break
} else {
fmt.Printf("Unrecognized option: %s\n", todo)
}
}
}
fmt.Println("Though this query has ended, its relics still slumber in New Argive.")
fmt.Scanln()
break
*/
2024-06-10 15:34:16 +00:00
default:
fmt.Println("Unrecognized command:", command)
break
}
}
}