TheMathemagicians/sevenkeys/main.go

74 lines
1.8 KiB
Go
Raw Normal View History

2024-05-28 14:29:13 +00:00
package main
import (
"flag"
"fmt"
2024-09-12 12:29:43 +00:00
"os"
2024-06-10 15:34:16 +00:00
"sevenkeys/cli"
2024-06-10 12:32:45 +00:00
"sevenkeys/database"
"sevenkeys/delverlens"
2024-06-10 15:34:16 +00:00
"sevenkeys/figlet"
"sevenkeys/logic"
2024-05-28 14:29:13 +00:00
)
const (
2024-10-04 11:06:59 +00:00
UpdateSubcommand string = "update"
2024-09-25 16:49:01 +00:00
ImportSubcommand string = "import"
2024-10-04 12:44:22 +00:00
SearchSubcommand string = "search"
)
2024-05-28 14:29:13 +00:00
func main() {
var profile string
flag.StringVar(&profile, "profile", "development", "The database profile to use.")
flag.Parse()
db := database.GetDatabaseFromConfig("config." + profile + ".json")
2024-09-05 11:22:02 +00:00
figlet.ReadFigletFonts()
2024-06-10 15:34:16 +00:00
cli.ShowSplashScreen()
2024-05-28 14:29:13 +00:00
2024-09-25 16:49:01 +00:00
// TODO: Decide in what form we need to retain this functionality if any
//cli.MainCliLoop(db)
2024-10-04 12:44:22 +00:00
importCmd := flag.NewFlagSet(ImportSubcommand, flag.ExitOnError)
2024-09-25 16:49:01 +00:00
storageArea := importCmd.String("storagearea", "", "The name of the StorageArea where cards should be imported.")
2024-10-04 12:44:22 +00:00
//searchCmd := flag.NewFlagSet(SearchSubcommand, flag.ExitOnError)
//name := searchCmd.String("name", "", "The card name to search for.")
if len(flag.Args()) == 0 {
2024-09-25 16:49:01 +00:00
fmt.Fprintln(os.Stderr, "Please specify a subcommand.")
os.Exit(1)
}
switch flag.Args()[0] {
2024-10-04 12:44:22 +00:00
case UpdateSubcommand:
cli.RunUpdateCheck(db)
break
2024-09-25 16:49:01 +00:00
case ImportSubcommand:
importCmd.Parse(flag.Args()[1:])
storageAreaId, err := logic.GetStorageAreaId(db, *storageArea)
if err == logic.ErrCouldNotGetStorageAreaId {
fmt.Fprintf(os.Stderr, "[sevenkeys] No storage area was selected, exiting.\n")
os.Exit(1)
}
logic.Check(err)
delverLensCards, err := delverlens.ParseExportFile(importCmd.Args()[0])
logic.Check(err)
2024-09-25 16:49:01 +00:00
err = logic.ImportDelverLensCards(db, delverLensCards, storageAreaId)
logic.Check(err)
break
2024-10-04 12:44:22 +00:00
case SearchSubcommand:
searchOptions, err := logic.GetAllStorageSearchOptions(db)
logic.Check(err)
logic.GenericSearch(searchOptions)
2024-10-04 11:06:59 +00:00
break
default:
2024-09-25 16:49:01 +00:00
fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1])
break
}
2024-05-28 14:29:13 +00:00
}