pcgamedb/cmd/import.go

42 lines
958 B
Go
Raw Normal View History

package cmd
import (
"github.com/spf13/cobra"
"go.uber.org/zap"
"pcgamedb/db"
"pcgamedb/log"
)
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)
}