pcgamedb/cmd/list.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

45 lines
841 B
Go

package cmd
import (
"pcgamedb/db"
"pcgamedb/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var listCmd = &cobra.Command{
Use: "list",
Long: "List game infos by filter",
Short: "List game infos by filter",
Run: listRun,
}
type listCommandConfig struct {
Unid bool
}
var listCmdCfg listCommandConfig
func init() {
listCmd.Flags().BoolVarP(&listCmdCfg.Unid, "unorganized", "u", false, "unorganized")
RootCmd.AddCommand(listCmd)
}
func listRun(cmd *cobra.Command, args []string) {
if listCmdCfg.Unid {
games, err := db.GetUnorganizedGameItems(-1)
if err != nil {
log.Logger.Error("Failed to get games", zap.Error(err))
}
for _, game := range games {
log.Logger.Info(
"Game",
zap.Any("game_id", game.ID),
zap.String("raw_name", game.RawName),
zap.String("name", game.Name),
)
}
}
}