TheMathemagicians/sevenkeys/cli/stashui.go

124 lines
2.7 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-06-11 09:43:30 +00:00
"sevenkeys/database"
2024-06-10 15:34:16 +00:00
"sevenkeys/logic"
)
var (
selectedCardPrintingId string
selectedCardPrintingSearchLine string
2024-06-11 09:43:30 +00:00
storageBoxLabel string
source string
cardCondition string
2024-06-11 09:57:02 +00:00
2024-06-11 15:28:17 +00:00
searchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "en",
}
2024-06-11 09:57:02 +00:00
searchOptions logic.SearchOptions
2024-06-10 15:34:16 +00:00
)
2024-06-11 16:02:02 +00:00
func getSearchCriteria() {
searchCriteria.SetCode = GetStringResponse("Set code:")
searchCriteria.Foil = GetTriadicResponse("Foil (y/n/E):")
searchCriteria.Promo = GetTriadicResponse("Promo (y/n/E):")
searchCriteria.Language = GetStringResponse("Language:")
}
2024-06-11 09:57:02 +00:00
func getSearchOptions(db *sql.DB) {
if searchOptions == nil {
fmt.Println("LOADING")
2024-06-11 15:28:17 +00:00
options, err := logic.GetAllSearchOptions(db, searchCriteria)
2024-06-11 09:57:02 +00:00
logic.Check(err)
searchOptions = options
fmt.Println("READY")
fmt.Println("RUN")
}
}
func getInfoDisplay(info string) string {
if info == "" {
return "[EMPTY]"
}
return info
}
2024-06-11 09:43:30 +00:00
func ShowStorageInfo() {
2024-06-11 09:57:02 +00:00
storageBoxDisplay := getInfoDisplay(storageBoxLabel)
sourceDisplay := getInfoDisplay(source)
conditionDisplay := getInfoDisplay(cardCondition)
fmt.Println("Storage location:", storageBoxDisplay, "|", "Source:", sourceDisplay, "|", "Condition:", conditionDisplay)
2024-06-11 09:43:30 +00:00
2024-06-10 15:34:16 +00:00
if selectedCardPrintingId != "" {
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
}
}
2024-06-11 09:43:30 +00:00
func GetStorageOptions() {
storageBoxLabel = GetStringResponse("Storage box label:")
source = GetStringResponse("Card source:")
cardCondition = GetStringResponse("Card condition:")
}
func InsertSelectedCard(db *sql.DB) {
if selectedCardPrintingId == "" {
fmt.Println("No card selected, please [search] for a card printing.")
return
}
2024-06-11 15:28:17 +00:00
if storageBoxLabel == "" || cardCondition == "" {
2024-06-11 09:43:30 +00:00
GetStorageOptions()
}
storageLocation := database.CardStorageLocation{
CardPrintingId: selectedCardPrintingId,
StorageBox: storageBoxLabel,
Source: source,
2024-06-11 09:57:11 +00:00
CardCondition: cardCondition,
2024-06-11 09:43:30 +00:00
}
2024-06-11 09:57:02 +00:00
err := logic.StoreCard(db, storageLocation)
logic.Check(err)
fmt.Println("Inserted card")
2024-06-11 09:43:30 +00:00
}
2024-06-11 09:57:02 +00:00
func StashCliLoop(db *sql.DB) {
2024-06-10 15:34:16 +00:00
var command string
for {
2024-06-11 09:43:30 +00:00
ShowStorageInfo()
2024-06-10 15:34:16 +00:00
command = GetStringResponse("SEVENKEYS (stash) $")
switch command {
case "back":
return
2024-06-11 09:43:30 +00:00
case "storage":
GetStorageOptions()
break
2024-06-11 16:02:02 +00:00
case "criteria":
getSearchCriteria()
break
2024-06-10 15:34:16 +00:00
case "search":
2024-06-11 09:57:02 +00:00
getSearchOptions(db)
2024-06-10 15:34:16 +00:00
var err error
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
logic.Check(err)
break
2024-06-11 09:43:30 +00:00
case "insert":
InsertSelectedCard(db)
break
2024-06-10 15:34:16 +00:00
default:
fmt.Println("Unrecognized command:", command)
2024-06-11 09:43:30 +00:00
break
2024-06-10 15:34:16 +00:00
}
}
}