TheMathemagicians/sevenkeys/cli/search.go

72 lines
1.6 KiB
Go

package cli
import (
"database/sql"
"fmt"
"sevenkeys/logic"
)
var (
searchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "",
}
shouldRefreshSearch bool = true
searchOptions logic.SearchOptions
)
func getSearchCriteria() {
searchCriteria.SetCode = GetStringResponse("Set code:")
searchCriteria.Foil = GetTriadicResponse("Foil (y/n/E):")
searchCriteria.Promo = GetTriadicResponse("Promo (y/n/E):")
searchCriteria.Language = GetStringResponse("Language:")
shouldRefreshSearch = true
}
func getTriadicDisplay(triadic logic.Triadic) string {
if triadic == logic.True {
return "True"
}
if triadic == logic.False {
return "False"
}
return "Either"
}
func showSearchCriteria() {
fmt.Println("SEARCH CRITERIA")
setCodeDisplay := getInfoDisplay(searchCriteria.SetCode)
foilDisplay := getTriadicDisplay(searchCriteria.Foil)
promoDisplay := getTriadicDisplay(searchCriteria.Promo)
languageDisplay := getInfoDisplay(searchCriteria.Language)
fmt.Println("Set code:", setCodeDisplay)
fmt.Println("Foil:", foilDisplay)
fmt.Println("Promo:", promoDisplay)
fmt.Println("Language:", languageDisplay)
fmt.Print("\n")
}
func showSelectedCard() {
selectedCardDisplay := getInfoDisplay(selectedCardPrintingSearchLine)
fmt.Println("Selected card:", selectedCardDisplay)
}
func getSearchOptions(db *sql.DB) {
if shouldRefreshSearch {
fmt.Println("LOADING")
options, err := logic.GetAllSearchOptions(db, searchCriteria)
logic.Check(err)
searchOptions = options
shouldRefreshSearch = false
fmt.Println("READY")
fmt.Println("RUN")
}
}