Only get options when searching

This commit is contained in:
The Magician 2024-06-11 10:57:02 +01:00
parent a6c2f73637
commit 74219fa7aa
3 changed files with 34 additions and 17 deletions

View File

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

View File

@ -14,10 +14,35 @@ var (
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() {
fmt.Println("Storage location:", storageBoxLabel, "|", "Source:", source)
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)
@ -46,10 +71,12 @@ func InsertSelectedCard(db *sql.DB) {
Source: source,
}
logic.StoreCard(db, storageLocation)
err := logic.StoreCard(db, storageLocation)
logic.Check(err)
fmt.Println("Inserted card")
}
func StashCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
func StashCliLoop(db *sql.DB) {
var command string
for {
@ -63,6 +90,7 @@ func StashCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
GetStorageOptions()
break
case "search":
getSearchOptions(db)
var err error
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
logic.Check(err)

View File

@ -1,15 +1,11 @@
package main
import (
"fmt"
"sevenkeys/cli"
"sevenkeys/database"
"sevenkeys/figlet"
"sevenkeys/logic"
)
var searchOptions logic.SearchOptions
func main() {
db := database.GetDatabaseFromConfig("config.json")
figlet.ReadFigletFonts()
@ -18,13 +14,7 @@ func main() {
cli.RunUpdateCheck(db)
fmt.Println("LOADING")
searchOptions, err := logic.GetAllSearchOptions(db)
logic.Check(err)
fmt.Println("READY")
fmt.Println("RUN")
cli.MainCliLoop(db, searchOptions)
cli.MainCliLoop(db)
/*
var selectedCardId string