Flesh out REPL UI

This commit is contained in:
The Magician 2024-06-11 10:43:30 +01:00
parent c474d3f8bf
commit a6c2f73637
3 changed files with 47 additions and 18 deletions

View File

@ -1,11 +1,12 @@
package cli
import (
"database/sql"
"fmt"
"sevenkeys/logic"
)
func MainCliLoop(searchOptions logic.SearchOptions) {
func MainCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
var command string
for {
@ -18,7 +19,7 @@ func MainCliLoop(searchOptions logic.SearchOptions) {
ShowSplashScreen()
break
case "stash":
StashCliLoop(searchOptions)
StashCliLoop(db, searchOptions)
break
default:
fmt.Println("Unrecognized command:", command)

View File

@ -1,38 +1,78 @@
package cli
import (
"database/sql"
"fmt"
"sevenkeys/database"
"sevenkeys/logic"
)
var (
selectedCardPrintingId string
selectedCardPrintingSearchLine string
storageBoxLabel string
source string
cardCondition string
)
func ShowSelectedCard() {
func ShowStorageInfo() {
fmt.Println("Storage location:", storageBoxLabel, "|", "Source:", source)
if selectedCardPrintingId != "" {
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
}
}
func StashCliLoop(searchOptions logic.SearchOptions) {
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) {
var command string
for {
ShowSelectedCard()
ShowStorageInfo()
command = GetStringResponse("SEVENKEYS (stash) $")
switch command {
case "back":
return
case "storage":
GetStorageOptions()
break
case "search":
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
}
}
}

View File

@ -24,21 +24,9 @@ func main() {
fmt.Println("READY")
fmt.Println("RUN")
cli.MainCliLoop(searchOptions)
cli.MainCliLoop(db, searchOptions)
/*
storageBox := logic.GetResponse("Enter storage box label:")
source := logic.GetResponse("Enter source:")
storageLocation := database.CardStorageLocation{
StorageBox: storageBox,
Source: source,
}
searchOptions, err := logic.GetAllSearchOptions(db)
logic.Check(err)
var selectedCardId string
var selectedCardSearchOption string = "None"
var lastOutput string