package cmd import ( "github.com/nitezs/pcgamedb/db" "github.com/nitezs/pcgamedb/log" "github.com/spf13/cobra" "go.uber.org/zap" ) type importCommandConfig struct { game string info string } var importCmdCfg importCommandConfig var importCmd = &cobra.Command{ Use: "import", Long: "import data from json files", Short: "import data from json files", Run: func(cmd *cobra.Command, args []string) { if importCmdCfg.game != "" { err := db.ImportGameItem(importCmdCfg.game) if err != nil { log.Logger.Error("Error importing game item", zap.Error(err)) } } if importCmdCfg.info != "" { err := db.ImportGameInfo(importCmdCfg.info) if err != nil { log.Logger.Error("Error importing game info", zap.Error(err)) } } }, } func init() { importCmd.Flags().StringVarP(&importCmdCfg.game, "game", "g", "", "Games file to import") importCmd.Flags().StringVarP(&importCmdCfg.info, "info", "i", "", "Games file to import") RootCmd.AddCommand(importCmd) }