github.com/loomnetwork/gamechain@v0.0.0-20200406110549-36c47eb97a92/cli/cmd/list_game_modes.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 listGameModesCmd = &cobra.Command{
    16  	Use:   "list_game_modes",
    17  	Short: "list game modes",
    18  	RunE: func(cmd *cobra.Command, args []string) error {
    19  		signer := auth.NewEd25519Signer(commonTxObjs.privateKey)
    20  		callerAddr := loom.Address{
    21  			ChainID: commonTxObjs.rpcClient.GetChainID(),
    22  			Local:   loom.LocalAddressFromPublicKey(signer.PublicKey()),
    23  		}
    24  
    25  		req := &zb_calls.ListGameModesRequest{}
    26  		var result zb_data.GameModeList
    27  		_, err := commonTxObjs.contract.StaticCall("ListGameModes", req, callerAddr, &result)
    28  		if err != nil {
    29  			return err
    30  		}
    31  
    32  		switch strings.ToLower(rootCmdArgs.outputFormat) {
    33  		case "json":
    34  			err := battleground_utility.PrintProtoMessageAsJsonToStdout(&result)
    35  			if err != nil {
    36  				return err
    37  			}
    38  		default:
    39  			for _, gameMode := range result.GameModes {
    40  				fmt.Printf("ID: %s\n", gameMode.ID)
    41  				fmt.Printf("Name: %s\n", gameMode.Name)
    42  				fmt.Printf("Description: %s\n", gameMode.Description)
    43  				fmt.Printf("Version: %s\n", gameMode.Version)
    44  				fmt.Printf("GameModeType: %s\n", gameMode.GameModeType)
    45  				fmt.Printf("Address: %s\n", gameMode.Address.String())
    46  				fmt.Printf("Owner: %s\n", gameMode.Owner.String())
    47  			}
    48  		}
    49  
    50  		return nil
    51  	},
    52  }
    53  
    54  func init() {
    55  	rootCmd.AddCommand(listGameModesCmd)
    56  }