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-10 15:34:16 +00:00
|
|
|
)
|
|
|
|
|
2024-06-11 09:43:30 +00:00
|
|
|
func ShowStorageInfo() {
|
|
|
|
fmt.Println("Storage location:", storageBoxLabel, "|", "Source:", source)
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
logic.StoreCard(db, storageLocation)
|
|
|
|
}
|
|
|
|
|
|
|
|
func StashCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
|
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":
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|