github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/cli/cmd/get_deck.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/loomnetwork/gamechain/tools/battleground_utility" 6 "github.com/loomnetwork/gamechain/types/zb/zb_calls" 7 "strings" 8 9 "github.com/loomnetwork/go-loom/auth" 10 "github.com/spf13/cobra" 11 ) 12 13 var getDeckCmdArgs struct { 14 userID string 15 deckID int64 16 version string 17 } 18 19 var getDeckCmd = &cobra.Command{ 20 Use: "get_deck", 21 Short: "gets deck for zombiebattleground by its id", 22 RunE: func(cmd *cobra.Command, args []string) error { 23 signer := auth.NewEd25519Signer(commonTxObjs.privateKey) 24 25 req := &zb_calls.GetDeckRequest{ 26 UserId: getDeckCmdArgs.userID, 27 DeckId: getDeckCmdArgs.deckID, 28 Version: getDeckCmdArgs.version, 29 } 30 var result zb_calls.GetDeckResponse 31 _, err := commonTxObjs.contract.Call("GetDeck", req, signer, &result) 32 if err != nil { 33 return err 34 } 35 36 switch strings.ToLower(rootCmdArgs.outputFormat) { 37 case "json": 38 err := battleground_utility.PrintProtoMessageAsJsonToStdout(&result) 39 if err != nil { 40 return err 41 } 42 default: 43 fmt.Printf("deck name: %v\n", result.Deck.Name) 44 fmt.Printf("deck id: %v\n", result.Deck.Id) 45 fmt.Printf("overlord id: %v\n", result.Deck.OverlordId) 46 for _, card := range result.Deck.Cards { 47 fmt.Printf("card: [%v], amount: %d\n", card.CardKey.String(), card.Amount) 48 } 49 } 50 return nil 51 }, 52 } 53 54 func init() { 55 rootCmd.AddCommand(getDeckCmd) 56 57 getDeckCmd.Flags().StringVarP(&getDeckCmdArgs.userID, "userId", "u", "loom", "UserId of account") 58 getDeckCmd.Flags().Int64VarP(&getDeckCmdArgs.deckID, "deckId", "", 0, "DeckId of account") 59 getDeckCmd.Flags().StringVarP(&getDeckCmdArgs.version, "version", "v", "v1", "Version") 60 61 _ = getDeckCmd.MarkFlagRequired("version") 62 }