Unify into single REPL

This commit is contained in:
The Magician 2024-06-12 21:33:50 +01:00
parent c45347ec25
commit 7031bc7b07
2 changed files with 23 additions and 42 deletions

View File

@ -2,23 +2,42 @@ package cli
import (
"database/sql"
"errors"
"fmt"
"os/exec"
"sevenkeys/logic"
)
func MainCliLoop(db *sql.DB) {
var command string
for {
ShowSplashScreen()
ShowStorageInfo()
command = GetStringResponse("SEVENKEYS $")
switch command {
case "quit":
return
case "splash":
ShowSplashScreen()
case "storage":
GetStorageOptions()
break
case "stash":
StashCliLoop(db)
case "criteria":
getSearchCriteria()
break
case "search":
getSearchOptions(db)
var err error
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
var exitError *exec.ExitError
if errors.As(err, &exitError) {
break
}
logic.Check(err)
break
case "insert":
InsertSelectedCard(db)
break
default:
fmt.Println("Unrecognized command:", command)

View File

@ -2,9 +2,7 @@ package cli
import (
"database/sql"
"errors"
"fmt"
"os/exec"
"sevenkeys/database"
"sevenkeys/logic"
)
@ -94,39 +92,3 @@ func InsertSelectedCard(db *sql.DB) {
logic.Check(err)
fmt.Println("Inserted card")
}
func StashCliLoop(db *sql.DB) {
var command string
for {
ShowStorageInfo()
command = GetStringResponse("SEVENKEYS (stash) $")
switch command {
case "back":
return
case "storage":
GetStorageOptions()
break
case "criteria":
getSearchCriteria()
break
case "search":
getSearchOptions(db)
var err error
selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
var exitError *exec.ExitError
if errors.As(err, &exitError) {
break
}
logic.Check(err)
break
case "insert":
InsertSelectedCard(db)
break
default:
fmt.Println("Unrecognized command:", command)
break
}
}
}