2024-11-17 00:29:04 -05:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"go.uber.org/zap"
|
2024-11-21 12:30:26 -05:00
|
|
|
"pcgamedb/db"
|
|
|
|
"pcgamedb/log"
|
2024-11-17 00:29:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|