108 lines
2.2 KiB
Go
108 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"sevenkeys/database"
|
|
"sevenkeys/logic"
|
|
)
|
|
|
|
var (
|
|
selectedCardPrintingId string
|
|
selectedCardPrintingSearchLine string
|
|
|
|
storageBoxLabel string
|
|
source string
|
|
cardCondition string
|
|
|
|
searchOptions logic.SearchOptions
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func ShowStorageInfo() {
|
|
storageBoxDisplay := getInfoDisplay(storageBoxLabel)
|
|
sourceDisplay := getInfoDisplay(source)
|
|
conditionDisplay := getInfoDisplay(cardCondition)
|
|
|
|
fmt.Println("Storage location:", storageBoxDisplay, "|", "Source:", sourceDisplay, "|", "Condition:", conditionDisplay)
|
|
|
|
if selectedCardPrintingId != "" {
|
|
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
|
|
}
|
|
}
|
|
|
|
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,
|
|
CardCondition: cardCondition,
|
|
}
|
|
|
|
err := logic.StoreCard(db, storageLocation)
|
|
logic.Check(err)
|
|
fmt.Println("Inserted card")
|
|
}
|
|
|
|
func StashCliLoop(db *sql.DB) {
|
|
var command string
|
|
|
|
for {
|
|
ShowStorageInfo()
|
|
command = GetStringResponse("SEVENKEYS (stash) $")
|
|
|
|
switch command {
|
|
case "back":
|
|
return
|
|
case "storage":
|
|
GetStorageOptions()
|
|
break
|
|
case "search":
|
|
getSearchOptions(db)
|
|
var err error
|
|
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
|
logic.Check(err)
|
|
break
|
|
case "insert":
|
|
InsertSelectedCard(db)
|
|
break
|
|
default:
|
|
fmt.Println("Unrecognized command:", command)
|
|
break
|
|
}
|
|
}
|
|
}
|