From c1f581f31270f475376d56802c4a97cb9f79e3d6 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 4 Oct 2024 21:51:05 +0100 Subject: [PATCH] Add storagearea subcommand --- sevenkeys/cli/mainui.go | 173 +++++++++++++++++++++------------------- sevenkeys/main.go | 31 +++++-- 2 files changed, 114 insertions(+), 90 deletions(-) diff --git a/sevenkeys/cli/mainui.go b/sevenkeys/cli/mainui.go index 3a97e88..f32f8bd 100644 --- a/sevenkeys/cli/mainui.go +++ b/sevenkeys/cli/mainui.go @@ -2,11 +2,8 @@ package cli import ( "database/sql" - "errors" "fmt" - "os/exec" "sevenkeys/database" - "sevenkeys/delverlens" "sevenkeys/logic" ) @@ -47,100 +44,110 @@ func MainCliLoop(db *sql.DB) { 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) { + /* + 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 - } - logic.Check(err) + */ + /* + case "a", "area": + options, err := logic.GetStorageAreaSearchOptions(db) + logic.Check(err) - output = "" - if cardLocation.CardPrintingId != previousCardPrintingId { - copiesInserted = 0 - } - break + 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:") + /* + case "d", "delverlens": + filename := GetStringResponse("Filename:") - cards, err := delverlens.ParseExportFile(filename) - logic.Check(err) + 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) + 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) + 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) + if len(locations) == 0 { + fmt.Println("No results found") + fmt.Scanln() 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 + 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 diff --git a/sevenkeys/main.go b/sevenkeys/main.go index 7a6edc2..6a8f402 100644 --- a/sevenkeys/main.go +++ b/sevenkeys/main.go @@ -7,14 +7,14 @@ import ( "sevenkeys/cli" "sevenkeys/database" "sevenkeys/delverlens" - "sevenkeys/figlet" "sevenkeys/logic" ) const ( - UpdateSubcommand string = "update" - ImportSubcommand string = "import" - SearchSubcommand string = "search" + UpdateSubcommand string = "update" + CreateStorageAreaSubcommand string = "createstorage" + ImportSubcommand string = "import" + SearchSubcommand string = "search" ) func main() { @@ -24,15 +24,14 @@ func main() { flag.Parse() db := database.GetDatabaseFromConfig("config." + profile + ".json") + /* Sad. figlet.ReadFigletFonts() cli.ShowSplashScreen() + */ // TODO: Decide in what form we need to retain this functionality if any //cli.MainCliLoop(db) - importCmd := flag.NewFlagSet(ImportSubcommand, flag.ExitOnError) - storageArea := importCmd.String("storagearea", "", "The name of the StorageArea where cards should be imported.") - //searchCmd := flag.NewFlagSet(SearchSubcommand, flag.ExitOnError) //name := searchCmd.String("name", "", "The card name to search for.") @@ -44,8 +43,26 @@ func main() { switch flag.Args()[0] { case UpdateSubcommand: cli.RunUpdateCheck(db) + break + case CreateStorageAreaSubcommand: + createStorageCmd := flag.NewFlagSet(CreateStorageAreaSubcommand, flag.ExitOnError) + storageAreaName := createStorageCmd.String("name", "", + "The name of the StorageArea to create.") + storageAreaType := createStorageCmd.String("type", "", + "The name of the StorageArea to create.") + + createStorageCmd.Parse(flag.Args()[1:]) + + storageArea := database.StorageArea{Name: *storageAreaName, StorageType: *storageAreaType} + err := logic.CreateStorageArea(db, storageArea) + logic.Check(err) + break case ImportSubcommand: + importCmd := flag.NewFlagSet(ImportSubcommand, flag.ExitOnError) + storageArea := importCmd.String("storagearea", "", + "The name of the StorageArea where cards should be imported.") + importCmd.Parse(flag.Args()[1:]) storageAreaId, err := logic.GetStorageAreaId(db, *storageArea)