Flesh out REPL UI
This commit is contained in:
parent
c474d3f8bf
commit
a6c2f73637
|
@ -1,11 +1,12 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sevenkeys/logic"
|
"sevenkeys/logic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MainCliLoop(searchOptions logic.SearchOptions) {
|
func MainCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
|
||||||
var command string
|
var command string
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -18,7 +19,7 @@ func MainCliLoop(searchOptions logic.SearchOptions) {
|
||||||
ShowSplashScreen()
|
ShowSplashScreen()
|
||||||
break
|
break
|
||||||
case "stash":
|
case "stash":
|
||||||
StashCliLoop(searchOptions)
|
StashCliLoop(db, searchOptions)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unrecognized command:", command)
|
fmt.Println("Unrecognized command:", command)
|
||||||
|
|
|
@ -1,38 +1,78 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sevenkeys/database"
|
||||||
"sevenkeys/logic"
|
"sevenkeys/logic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
selectedCardPrintingId string
|
selectedCardPrintingId string
|
||||||
selectedCardPrintingSearchLine string
|
selectedCardPrintingSearchLine string
|
||||||
|
|
||||||
|
storageBoxLabel string
|
||||||
|
source string
|
||||||
|
cardCondition string
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShowSelectedCard() {
|
func ShowStorageInfo() {
|
||||||
|
fmt.Println("Storage location:", storageBoxLabel, "|", "Source:", source)
|
||||||
|
|
||||||
if selectedCardPrintingId != "" {
|
if selectedCardPrintingId != "" {
|
||||||
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
|
fmt.Println("Selected card:", selectedCardPrintingSearchLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StashCliLoop(searchOptions logic.SearchOptions) {
|
func GetStorageOptions() {
|
||||||
|
storageBoxLabel = GetStringResponse("Storage box label:")
|
||||||
|
source = GetStringResponse("Card source:")
|
||||||
|
cardCondition = GetStringResponse("Card condition:")
|
||||||
|
}
|
||||||
|
|
||||||
|
func InsertSelectedCard(db *sql.DB) {
|
||||||
|
if selectedCardPrintingId == "" {
|
||||||
|
fmt.Println("No card selected, please [search] for a card printing.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if storageBoxLabel == "" {
|
||||||
|
GetStorageOptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
storageLocation := database.CardStorageLocation{
|
||||||
|
CardPrintingId: selectedCardPrintingId,
|
||||||
|
StorageBox: storageBoxLabel,
|
||||||
|
Source: source,
|
||||||
|
}
|
||||||
|
|
||||||
|
logic.StoreCard(db, storageLocation)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StashCliLoop(db *sql.DB, searchOptions logic.SearchOptions) {
|
||||||
var command string
|
var command string
|
||||||
|
|
||||||
for {
|
for {
|
||||||
ShowSelectedCard()
|
ShowStorageInfo()
|
||||||
command = GetStringResponse("SEVENKEYS (stash) $")
|
command = GetStringResponse("SEVENKEYS (stash) $")
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case "back":
|
case "back":
|
||||||
return
|
return
|
||||||
|
case "storage":
|
||||||
|
GetStorageOptions()
|
||||||
|
break
|
||||||
case "search":
|
case "search":
|
||||||
var err error
|
var err error
|
||||||
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
||||||
logic.Check(err)
|
logic.Check(err)
|
||||||
break
|
break
|
||||||
|
case "insert":
|
||||||
|
InsertSelectedCard(db)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unrecognized command:", command)
|
fmt.Println("Unrecognized command:", command)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,9 @@ func main() {
|
||||||
fmt.Println("READY")
|
fmt.Println("READY")
|
||||||
fmt.Println("RUN")
|
fmt.Println("RUN")
|
||||||
|
|
||||||
cli.MainCliLoop(searchOptions)
|
cli.MainCliLoop(db, searchOptions)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
storageBox := logic.GetResponse("Enter storage box label:")
|
|
||||||
source := logic.GetResponse("Enter source:")
|
|
||||||
|
|
||||||
storageLocation := database.CardStorageLocation{
|
|
||||||
StorageBox: storageBox,
|
|
||||||
Source: source,
|
|
||||||
}
|
|
||||||
|
|
||||||
searchOptions, err := logic.GetAllSearchOptions(db)
|
|
||||||
logic.Check(err)
|
|
||||||
|
|
||||||
var selectedCardId string
|
var selectedCardId string
|
||||||
var selectedCardSearchOption string = "None"
|
var selectedCardSearchOption string = "None"
|
||||||
var lastOutput string
|
var lastOutput string
|
||||||
|
|
Loading…
Reference in New Issue