2024-06-10 15:34:16 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2024-06-11 09:43:30 +00:00
|
|
|
"database/sql"
|
2024-06-12 20:33:50 +00:00
|
|
|
"errors"
|
2024-06-10 15:34:16 +00:00
|
|
|
"fmt"
|
2024-08-20 14:28:49 +00:00
|
|
|
"os"
|
2024-06-12 20:33:50 +00:00
|
|
|
"os/exec"
|
2024-08-20 11:57:36 +00:00
|
|
|
"sevenkeys/database"
|
2024-06-12 20:33:50 +00:00
|
|
|
"sevenkeys/logic"
|
2024-06-10 15:34:16 +00:00
|
|
|
)
|
|
|
|
|
2024-06-12 22:37:13 +00:00
|
|
|
var output string
|
|
|
|
|
2024-06-11 09:57:02 +00:00
|
|
|
func MainCliLoop(db *sql.DB) {
|
2024-06-10 15:34:16 +00:00
|
|
|
var command string
|
2024-09-07 18:07:48 +00:00
|
|
|
|
2024-08-20 14:28:49 +00:00
|
|
|
var selectedStorageArea database.StorageArea
|
2024-09-05 09:53:14 +00:00
|
|
|
var cardLocation database.CardLocation
|
2024-06-10 15:34:16 +00:00
|
|
|
|
2024-09-07 18:07:48 +00:00
|
|
|
var insertSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
|
|
|
|
SetCode: "",
|
|
|
|
Foil: logic.Either,
|
|
|
|
Promo: logic.Either,
|
|
|
|
Language: "en",
|
|
|
|
}
|
|
|
|
var insertSearchOptions logic.InsertSearchOptions
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
// TODO: Add the ability to modify this
|
2024-09-07 23:24:24 +00:00
|
|
|
var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
|
|
|
|
SetCode: "",
|
2024-09-16 16:44:57 +00:00
|
|
|
Foil: logic.True,
|
2024-09-07 23:24:24 +00:00
|
|
|
Promo: logic.Either,
|
|
|
|
Language: "en",
|
|
|
|
}
|
|
|
|
|
2024-06-10 15:34:16 +00:00
|
|
|
for {
|
2024-06-12 20:33:50 +00:00
|
|
|
ShowSplashScreen()
|
2024-08-20 14:28:49 +00:00
|
|
|
showStorageInfo(os.Stdout, selectedStorageArea)
|
2024-09-07 18:07:48 +00:00
|
|
|
showInsertSearchCriteria(insertSearchCriteria)
|
2024-06-12 22:37:13 +00:00
|
|
|
showSelectedCard()
|
|
|
|
showCopiesInserted()
|
2024-06-12 20:33:50 +00:00
|
|
|
|
2024-06-10 15:34:16 +00:00
|
|
|
command = GetStringResponse("SEVENKEYS $")
|
|
|
|
|
2024-08-20 11:57:36 +00:00
|
|
|
var err error
|
|
|
|
|
2024-06-10 15:34:16 +00:00
|
|
|
switch command {
|
2024-06-14 09:50:46 +00:00
|
|
|
case "q", "quit":
|
2024-06-10 15:34:16 +00:00
|
|
|
return
|
2024-08-20 11:57:36 +00:00
|
|
|
case "n", "newstorage":
|
|
|
|
var storageArea database.StorageArea
|
|
|
|
storageArea.Name = GetStringResponse("Storage area name:")
|
2024-08-20 17:50:38 +00:00
|
|
|
storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):")
|
2024-08-20 11:57:36 +00:00
|
|
|
err = logic.CreateStorageArea(db, storageArea)
|
|
|
|
logic.Check(err)
|
|
|
|
break
|
2024-08-20 17:00:23 +00:00
|
|
|
case "a", "area":
|
|
|
|
area, err := logic.SelectStorageArea(db)
|
|
|
|
logic.Check(err)
|
|
|
|
selectedStorageArea = area
|
2024-09-05 09:53:14 +00:00
|
|
|
cardLocation.StorageAreaId = area.Id
|
2024-06-14 09:50:46 +00:00
|
|
|
break
|
|
|
|
case "c", "criteria":
|
2024-09-07 18:07:48 +00:00
|
|
|
insertSearchCriteria = getSearchCriteria()
|
2024-06-12 20:33:50 +00:00
|
|
|
break
|
2024-06-14 09:50:46 +00:00
|
|
|
case "s", "search":
|
2024-09-07 18:07:48 +00:00
|
|
|
if shouldRefreshSearch {
|
|
|
|
insertSearchOptions = getSearchOptions(db, insertSearchCriteria)
|
|
|
|
}
|
2024-06-12 22:37:13 +00:00
|
|
|
|
2024-09-05 09:53:14 +00:00
|
|
|
var previousCardPrintingId = cardLocation.CardPrintingId
|
2024-06-12 22:37:13 +00:00
|
|
|
|
2024-09-16 16:59:44 +00:00
|
|
|
pk, searchLine, err := logic.GenericSearch(insertSearchOptions)
|
2024-09-07 18:07:48 +00:00
|
|
|
cardLocation.CardPrintingId = pk
|
2024-09-16 16:59:44 +00:00
|
|
|
selectedCardPrintingSearchLine = searchLine
|
2024-09-07 18:07:48 +00:00
|
|
|
|
2024-06-12 20:33:50 +00:00
|
|
|
var exitError *exec.ExitError
|
|
|
|
if errors.As(err, &exitError) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
logic.Check(err)
|
2024-06-12 22:37:13 +00:00
|
|
|
|
|
|
|
output = ""
|
2024-09-05 09:53:14 +00:00
|
|
|
if cardLocation.CardPrintingId != previousCardPrintingId {
|
2024-06-12 22:37:13 +00:00
|
|
|
copiesInserted = 0
|
|
|
|
}
|
2024-06-10 15:34:16 +00:00
|
|
|
break
|
2024-06-14 09:50:46 +00:00
|
|
|
case "i", "insert":
|
2024-09-05 09:53:14 +00:00
|
|
|
insertSelectedCard(db, selectedStorageArea, cardLocation)
|
|
|
|
break
|
|
|
|
case "l", "locate":
|
2024-09-07 23:24:24 +00:00
|
|
|
filename := GetStringResponse("Filename:")
|
|
|
|
cardNames, err := logic.GetCardNamesFromFile(filename)
|
|
|
|
logic.Check(err)
|
2024-09-07 18:07:48 +00:00
|
|
|
|
2024-09-07 23:24:24 +00:00
|
|
|
locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria)
|
2024-09-05 09:53:14 +00:00
|
|
|
logic.Check(err)
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
if len(locations) == 0 {
|
|
|
|
fmt.Println("No results found")
|
|
|
|
fmt.Scanln()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2024-09-05 09:53:14 +00:00
|
|
|
for _, location := range locations {
|
2024-09-13 11:32:18 +00:00
|
|
|
description := logic.GetLocationDescription(location)
|
|
|
|
fmt.Println(description)
|
|
|
|
|
|
|
|
for true {
|
|
|
|
todo := GetStringResponse("TODO:")
|
|
|
|
|
|
|
|
if todo == "r" {
|
|
|
|
logic.RemoveFromStorage(db, location)
|
2024-09-13 19:06:16 +00:00
|
|
|
break
|
2024-09-13 11:32:18 +00:00
|
|
|
} else if todo == "n" {
|
2024-09-13 19:05:28 +00:00
|
|
|
break
|
2024-09-13 11:32:18 +00:00
|
|
|
} else {
|
|
|
|
fmt.Printf("Unrecognized option: %s\n", todo)
|
|
|
|
}
|
|
|
|
}
|
2024-09-05 09:53:14 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 19:16:17 +00:00
|
|
|
fmt.Println("Though this query has ended, its relics still slumber in New Argive.")
|
2024-09-13 11:32:18 +00:00
|
|
|
fmt.Scanln()
|
2024-06-10 15:34:16 +00:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
fmt.Println("Unrecognized command:", command)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|