github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/cli/cmd/get_game_mode.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  	"github.com/loomnetwork/gamechain/types/zb/zb_data"
     8  	"strings"
     9  
    10  	"github.com/loomnetwork/go-loom"
    11  	"github.com/loomnetwork/go-loom/auth"
    12  	"github.com/spf13/cobra"
    13  )
    14  
    15  var getGameModeCmdArgs struct {
    16  	ID string
    17  }
    18  
    19  var getGameModeCmd = &cobra.Command{
    20  	Use:   "get_game_mode",
    21  	Short: "get game mode by id",
    22  	RunE: func(cmd *cobra.Command, args []string) error {
    23  		signer := auth.NewEd25519Signer(commonTxObjs.privateKey)
    24  		callerAddr := loom.Address{
    25  			ChainID: commonTxObjs.rpcClient.GetChainID(),
    26  			Local:   loom.LocalAddressFromPublicKey(signer.PublicKey()),
    27  		}
    28  
    29  		var req zb_calls.GetGameModeRequest
    30  		var gameMode = zb_data.GameMode{}
    31  
    32  		req.ID = getGameModeCmdArgs.ID
    33  
    34  		_, err := commonTxObjs.contract.StaticCall("GetGameMode", &req, callerAddr, &gameMode)
    35  		if err != nil {
    36  			return err
    37  		}
    38  
    39  		switch strings.ToLower(rootCmdArgs.outputFormat) {
    40  		case "json":
    41  			err := battleground_utility.PrintProtoMessageAsJsonToStdout(&gameMode)
    42  			if err != nil {
    43  				return err
    44  			}
    45  		default:
    46  			fmt.Printf("found game mode: %+v", gameMode)
    47  		}
    48  
    49  		return nil
    50  	},
    51  }
    52  
    53  func init() {
    54  	rootCmd.AddCommand(getGameModeCmd)
    55  	getGameModeCmd.Flags().StringVar(&getGameModeCmdArgs.ID, "id", "", "id of the game mode")
    56  }