package main import ( "flag" "fmt" "os" "sevenkeys/cli" "sevenkeys/database" "sevenkeys/delverlens" "sevenkeys/figlet" "sevenkeys/logic" ) const ( ImportSubcommand string = "import" ) func main() { var profile string flag.StringVar(&profile, "profile", "development", "The database profile to use.") flag.Parse() db := database.GetDatabaseFromConfig("config." + profile + ".json") figlet.ReadFigletFonts() cli.ShowSplashScreen() cli.RunUpdateCheck(db) // TODO: Decide in what form we need to retain this functionality if any //cli.MainCliLoop(db) importCmd := flag.NewFlagSet("import", flag.ExitOnError) storageArea := importCmd.String("storagearea", "", "The name of the StorageArea where cards should be imported.") if len(flag.Args()) == 0 { fmt.Fprintln(os.Stderr, "Please specify a subcommand.") os.Exit(1) } switch flag.Args()[0] { 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) err = logic.ImportDelverLensCards(db, delverLensCards, storageAreaId) logic.Check(err) break default: fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1]) break } }