Add storagearea subcommand
This commit is contained in:
parent
f7e0a713f6
commit
c1f581f312
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue