2024-06-10 15:34:16 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2024-06-11 09:43:30 +00:00
|
|
|
"database/sql"
|
2024-06-12 20:33:50 +00:00
|
|
|
"errors"
|
2024-06-10 15:34:16 +00:00
|
|
|
"fmt"
|
2024-06-12 20:33:50 +00:00
|
|
|
"os/exec"
|
|
|
|
"sevenkeys/logic"
|
2024-06-10 15:34:16 +00:00
|
|
|
)
|
|
|
|
|
2024-06-12 22:37:13 +00:00
|
|
|
var output string
|
|
|
|
|
|
|
|
func showOutput() {
|
|
|
|
if output != "" {
|
|
|
|
fmt.Println(output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-11 09:57:02 +00:00
|
|
|
func MainCliLoop(db *sql.DB) {
|
2024-06-10 15:34:16 +00:00
|
|
|
var command string
|
|
|
|
|
|
|
|
for {
|
2024-06-12 20:33:50 +00:00
|
|
|
ShowSplashScreen()
|
2024-06-12 22:37:13 +00:00
|
|
|
showStorageInfo()
|
|
|
|
showSearchCriteria()
|
|
|
|
showSelectedCard()
|
|
|
|
showCopiesInserted()
|
2024-06-12 20:33:50 +00:00
|
|
|
|
2024-06-10 15:34:16 +00:00
|
|
|
command = GetStringResponse("SEVENKEYS $")
|
|
|
|
|
|
|
|
switch command {
|
|
|
|
case "quit":
|
|
|
|
return
|
2024-06-12 20:33:50 +00:00
|
|
|
case "storage":
|
2024-06-12 22:37:13 +00:00
|
|
|
getStorageOptions()
|
2024-06-12 20:33:50 +00:00
|
|
|
break
|
|
|
|
case "criteria":
|
|
|
|
getSearchCriteria()
|
|
|
|
break
|
|
|
|
case "search":
|
|
|
|
getSearchOptions(db)
|
2024-06-12 22:37:13 +00:00
|
|
|
|
|
|
|
var previousCardPrintingId = cardStorageLocation.CardPrintingId
|
|
|
|
|
2024-06-12 20:33:50 +00:00
|
|
|
var err error
|
2024-06-12 22:37:13 +00:00
|
|
|
cardStorageLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
|
2024-06-12 20:33:50 +00:00
|
|
|
var exitError *exec.ExitError
|
|
|
|
if errors.As(err, &exitError) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
logic.Check(err)
|
2024-06-12 22:37:13 +00:00
|
|
|
|
|
|
|
output = ""
|
|
|
|
if cardStorageLocation.CardPrintingId != previousCardPrintingId {
|
|
|
|
copiesInserted = 0
|
|
|
|
}
|
2024-06-10 15:34:16 +00:00
|
|
|
break
|
2024-06-12 20:33:50 +00:00
|
|
|
case "insert":
|
2024-06-12 22:37:13 +00:00
|
|
|
insertSelectedCard(db)
|
2024-06-10 15:34:16 +00:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
fmt.Println("Unrecognized command:", command)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|