TheMathemagicians/sevenkeys/cli/stashui.go

108 lines
2.2 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
searchOptions logic.SearchOptions
2024-06-10 15:34:16 +00:00
)
2024-06-11 09:57:02 +00:00
func getSearchOptions(db *sql.DB) {
if searchOptions == nil {
fmt.Println("LOADING")
options, err := logic.GetAllSearchOptions(db)
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
}
if storageBoxLabel == "" {
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-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
}
}
}