pcgamedb/cmd/import.go
nite07 304517e241
Some checks failed
release / goreleaser (push) Failing after 2m23s
docker / prepare-and-build (push) Failing after 2m55s
trans to private
2024-11-20 19:09:04 +08:00

42 lines
958 B
Go

package cmd
import (
"pcgamedb/db"
"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)
}