package cmd

import (
	"encoding/json"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"strconv"
	"vikingar/cmd/config"
)

var (
	TProCmd = &cobra.Command{
		Use:   "tPro",
		Short: "用于显示tPro信息",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) == 0 {
				return
			}
			protoId, err := strconv.Atoi(args[0])
			if err != nil {
				panic(err)
			}
			reqData := viper.Get(args[0])
			req := config.ProtoRequestMap[protoId]
			resp := config.ProtoResponseMap[protoId]
			jsonStr, err := json.Marshal(reqData)
			if err != nil {
				panic(err)
			}
			if err = json.Unmarshal([]byte(jsonStr), &req); err != nil {
				panic(err)
			}
			TproClient.Do(req, resp, uint16(protoId))
		},
	}
)
