Add storagearea subcommand

This commit is contained in:
The Magician 2024-10-04 21:51:05 +01:00
parent f7e0a713f6
commit c1f581f312
2 changed files with 114 additions and 90 deletions

View File

@ -2,11 +2,8 @@ package cli
import ( import (
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"os/exec"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/delverlens"
"sevenkeys/logic" "sevenkeys/logic"
) )
@ -47,100 +44,110 @@ func MainCliLoop(db *sql.DB) {
var err error var err error
switch command { switch command {
case "q", "quit": /*
return case "q", "quit":
case "n", "newstorage": return
var storageArea database.StorageArea */
storageArea.Name = GetStringResponse("Storage area name:") /*
storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):") case "n", "newstorage":
err = logic.CreateStorageArea(db, storageArea) var storageArea database.StorageArea
logic.Check(err) storageArea.Name = GetStringResponse("Storage area name:")
break storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):")
case "a", "area": err = logic.CreateStorageArea(db, storageArea)
options, err := logic.GetStorageAreaSearchOptions(db) logic.Check(err)
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 break
} */
logic.Check(err) /*
case "a", "area":
options, err := logic.GetStorageAreaSearchOptions(db)
logic.Check(err)
output = "" id, _, err := logic.GenericSearch(options)
if cardLocation.CardPrintingId != previousCardPrintingId { logic.Check(err)
copiesInserted = 0
} //selectedStorageAreaName = name
break // 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": case "i", "insert":
err := logic.StoreCard(db, cardLocation) err := logic.StoreCard(db, cardLocation)
logic.Check(err) logic.Check(err)
copiesInserted++ copiesInserted++
break break
case "d", "delverlens": /*
filename := GetStringResponse("Filename:") case "d", "delverlens":
filename := GetStringResponse("Filename:")
cards, err := delverlens.ParseExportFile(filename) cards, err := delverlens.ParseExportFile(filename)
logic.Check(err) logic.Check(err)
err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId) err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId)
logic.Check(err) logic.Check(err)
break break
case "l", "locate": */
filename := GetStringResponse("Filename:") /*
cardNames, err := logic.GetCardNamesFromFile(filename) case "l", "locate":
logic.Check(err) filename := GetStringResponse("Filename:")
cardNames, err := logic.GetCardNamesFromFile(filename)
logic.Check(err)
locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria) locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria)
logic.Check(err) logic.Check(err)
if len(locations) == 0 { if len(locations) == 0 {
fmt.Println("No results found") fmt.Println("No results found")
fmt.Scanln() 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 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.") for _, location := range locations {
fmt.Scanln() description := logic.GetLocationDescription(location)
break 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: default:
fmt.Println("Unrecognized command:", command) fmt.Println("Unrecognized command:", command)
break break

View File

@ -7,14 +7,14 @@ import (
"sevenkeys/cli" "sevenkeys/cli"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/delverlens" "sevenkeys/delverlens"
"sevenkeys/figlet"
"sevenkeys/logic" "sevenkeys/logic"
) )
const ( const (
UpdateSubcommand string = "update" UpdateSubcommand string = "update"
ImportSubcommand string = "import" CreateStorageAreaSubcommand string = "createstorage"
SearchSubcommand string = "search" ImportSubcommand string = "import"
SearchSubcommand string = "search"
) )
func main() { func main() {
@ -24,15 +24,14 @@ func main() {
flag.Parse() flag.Parse()
db := database.GetDatabaseFromConfig("config." + profile + ".json") db := database.GetDatabaseFromConfig("config." + profile + ".json")
/* Sad.
figlet.ReadFigletFonts() figlet.ReadFigletFonts()
cli.ShowSplashScreen() cli.ShowSplashScreen()
*/
// TODO: Decide in what form we need to retain this functionality if any // TODO: Decide in what form we need to retain this functionality if any
//cli.MainCliLoop(db) //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) //searchCmd := flag.NewFlagSet(SearchSubcommand, flag.ExitOnError)
//name := searchCmd.String("name", "", "The card name to search for.") //name := searchCmd.String("name", "", "The card name to search for.")
@ -44,8 +43,26 @@ func main() {
switch flag.Args()[0] { switch flag.Args()[0] {
case UpdateSubcommand: case UpdateSubcommand:
cli.RunUpdateCheck(db) 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 break
case ImportSubcommand: 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:]) importCmd.Parse(flag.Args()[1:])
storageAreaId, err := logic.GetStorageAreaId(db, *storageArea) storageAreaId, err := logic.GetStorageAreaId(db, *storageArea)