package cli import ( "database/sql" "errors" "fmt" "os" "os/exec" "sevenkeys/database" "sevenkeys/logic" ) var output string func MainCliLoop(db *sql.DB) { var command string var selectedStorageArea database.StorageArea var cardLocation database.CardLocation for { ShowSplashScreen() showStorageInfo(os.Stdout, selectedStorageArea) showSearchCriteria() showSelectedCard() showCopiesInserted() command = GetStringResponse("SEVENKEYS $") var err error switch command { case "q", "quit": return case "n", "newstorage": var storageArea database.StorageArea storageArea.Name = GetStringResponse("Storage area name:") storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):") err = logic.CreateStorageArea(db, storageArea) logic.Check(err) break case "a", "area": area, err := logic.SelectStorageArea(db) logic.Check(err) selectedStorageArea = area cardLocation.StorageAreaId = area.Id break case "c", "criteria": getSearchCriteria() break case "s", "search": getSearchOptions(db) var previousCardPrintingId = cardLocation.CardPrintingId cardLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions) var exitError *exec.ExitError if errors.As(err, &exitError) { break } logic.Check(err) output = "" if cardLocation.CardPrintingId != previousCardPrintingId { copiesInserted = 0 } break case "i", "insert": insertSelectedCard(db, selectedStorageArea, cardLocation) break case "l", "locate": cardName := GetStringResponse("Card name:") locations, err := logic.LocateCards(db, cardName) logic.Check(err) for _, location := range locations { fmt.Printf("%s (%s %s) [%s]", location.CardName, location.SetCode, location.CollectorNumber, location.Language) if location.IsFoil { fmt.Printf(" FOIL") } if location.IsPromo { fmt.Printf(" PROMO") } fmt.Printf(" in %s \"%s\" at position %d\n", location.StorageAreaType, location.StorageAreaName, location.Position) } fmt.Scanln() break default: fmt.Println("Unrecognized command:", command) break } } }