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 ( import (
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"os/exec"
"sevenkeys/logic"
) )
func MainCliLoop(db *sql.DB) { func MainCliLoop(db *sql.DB) {
var command string var command string
for { for {
ShowSplashScreen()
ShowStorageInfo()
command = GetStringResponse("SEVENKEYS $") command = GetStringResponse("SEVENKEYS $")
switch command { switch command {
case "quit": case "quit":
return return
case "splash": case "storage":
ShowSplashScreen() GetStorageOptions()
break break
case "stash": case "criteria":
StashCliLoop(db) 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 break
default: default:
fmt.Println("Unrecognized command:", command) fmt.Println("Unrecognized command:", command)

View File

@ -2,9 +2,7 @@ package cli
import ( import (
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"os/exec"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/logic" "sevenkeys/logic"
) )
@ -94,39 +92,3 @@ func InsertSelectedCard(db *sql.DB) {
logic.Check(err) logic.Check(err)
fmt.Println("Inserted card") 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
}
}
}