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 (
"database/sql"
"errors"
"fmt"
"os/exec"
"sevenkeys/database"
"sevenkeys/delverlens"
"sevenkeys/logic"
)
@ -47,8 +44,11 @@ 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:")
@ -56,6 +56,8 @@ func MainCliLoop(db *sql.DB) {
err = logic.CreateStorageArea(db, storageArea)
logic.Check(err)
break
*/
/*
case "a", "area":
options, err := logic.GetStorageAreaSearchOptions(db)
logic.Check(err)
@ -92,11 +94,13 @@ func MainCliLoop(db *sql.DB) {
copiesInserted = 0
}
break
*/
case "i", "insert":
err := logic.StoreCard(db, cardLocation)
logic.Check(err)
copiesInserted++
break
/*
case "d", "delverlens":
filename := GetStringResponse("Filename:")
@ -106,6 +110,8 @@ func MainCliLoop(db *sql.DB) {
err = logic.ImportDelverLensCards(db, cards, cardLocation.StorageAreaId)
logic.Check(err)
break
*/
/*
case "l", "locate":
filename := GetStringResponse("Filename:")
cardNames, err := logic.GetCardNamesFromFile(filename)
@ -141,6 +147,7 @@ func MainCliLoop(db *sql.DB) {
fmt.Println("Though this query has ended, its relics still slumber in New Argive.")
fmt.Scanln()
break
*/
default:
fmt.Println("Unrecognized command:", command)
break

View File

@ -7,12 +7,12 @@ import (
"sevenkeys/cli"
"sevenkeys/database"
"sevenkeys/delverlens"
"sevenkeys/figlet"
"sevenkeys/logic"
)
const (
UpdateSubcommand string = "update"
CreateStorageAreaSubcommand string = "createstorage"
ImportSubcommand string = "import"
SearchSubcommand string = "search"
)
@ -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)