package cli import ( "database/sql" "errors" "fmt" "os/exec" "sevenkeys/database" "sevenkeys/delverlens" "sevenkeys/logic" ) var output string func MainCliLoop(db *sql.DB) { var command string //var selectedStorageAreaName string var cardLocation database.CardLocation var insertSearchCriteria logic.SearchCriteria = logic.SearchCriteria{ SetCode: "", Foil: logic.Either, Promo: logic.Either, Language: "en", } var insertSearchOptions logic.InsertSearchOptions // TODO: Add the ability to modify this var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{ SetCode: "", Foil: logic.True, Promo: logic.Either, Language: "en", } for { ShowSplashScreen() // TODO: Fix this //showStorageInfo(os.Stdout, selectedStorageAreaName) showInsertSearchCriteria(insertSearchCriteria) 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": options, err := logic.GetStorageAreaSearchOptions(db) logic.Check(err) id, _, err := logic.GenericSearch(options) logic.Check(err) //selectedStorageAreaName = name // TODO: Make db call to cache StorageArea once we have the ID cardLocation.StorageAreaId = id break case "c", "criteria": insertSearchCriteria = getSearchCriteria() break case "s", "search": if shouldRefreshSearch { insertSearchOptions = getSearchOptions(db, insertSearchCriteria) } var previousCardPrintingId = cardLocation.CardPrintingId pk, searchLine, err := logic.GenericSearch(insertSearchOptions) cardLocation.CardPrintingId = pk selectedCardPrintingSearchLine = searchLine var exitError *exec.ExitError if errors.As(err, &exitError) { break } logic.Check(err) output = "" if cardLocation.CardPrintingId != previousCardPrintingId { copiesInserted = 0 } break case "i", "insert": err := logic.StoreCard(db, cardLocation) logic.Check(err) copiesInserted++ break case "d", "delverlens": filename := GetStringResponse("Filename:") cards, err := delverlens.ParseExportFile(filename) logic.Check(err) err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId) logic.Check(err) break case "l", "locate": filename := GetStringResponse("Filename:") cardNames, err := logic.GetCardNamesFromFile(filename) logic.Check(err) locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria) logic.Check(err) if len(locations) == 0 { fmt.Println("No results found") fmt.Scanln() break } for _, location := range locations { description := logic.GetLocationDescription(location) fmt.Println(description) for true { todo := GetStringResponse("TODO:") if todo == "r" { logic.RemoveFromStorage(db, location) break } else if todo == "n" { break } else { fmt.Printf("Unrecognized option: %s\n", todo) } } } fmt.Println("Though this query has ended, its relics still slumber in New Argive.") fmt.Scanln() break default: fmt.Println("Unrecognized command:", command) break } } }