github.com/lino-network/lino@v0.6.11/x/bandwidth/client/cli/query.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/cosmos/cosmos-sdk/client"
     7  	"github.com/cosmos/cosmos-sdk/codec"
     8  	"github.com/spf13/cobra"
     9  
    10  	// linotypes "github.com/lino-network/lino/types"
    11  	"github.com/lino-network/lino/utils"
    12  	"github.com/lino-network/lino/x/bandwidth/model"
    13  	"github.com/lino-network/lino/x/bandwidth/types"
    14  )
    15  
    16  func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
    17  	cmd := &cobra.Command{
    18  		Use:                        types.ModuleName,
    19  		Short:                      "Querying commands for the bandwidth module",
    20  		DisableFlagParsing:         true,
    21  		SuggestionsMinimumDistance: 2,
    22  		RunE:                       client.ValidateCmd,
    23  	}
    24  	cmd.AddCommand(client.GetCommands(
    25  		getCmdInfo(cdc),
    26  		getCmdBlock(cdc),
    27  		getCmdApp(cdc),
    28  	)...)
    29  	return cmd
    30  }
    31  
    32  // GetCmdInfo -
    33  func getCmdInfo(cdc *codec.Codec) *cobra.Command {
    34  	return &cobra.Command{
    35  		Use:   "info",
    36  		Short: "info",
    37  		Args:  cobra.ExactArgs(0),
    38  		RunE: func(cmd *cobra.Command, args []string) error {
    39  			uri := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBandwidthInfo)
    40  			rst := model.BandwidthInfo{}
    41  			return utils.CLIQueryJSONPrint(cdc, uri, nil,
    42  				func() interface{} { return &rst })
    43  		},
    44  	}
    45  }
    46  
    47  // GetCmdBlock -
    48  func getCmdBlock(cdc *codec.Codec) *cobra.Command {
    49  	return &cobra.Command{
    50  		Use:   "block",
    51  		Short: "block",
    52  		Args:  cobra.ExactArgs(0),
    53  		RunE: func(cmd *cobra.Command, args []string) error {
    54  			uri := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBlockInfo)
    55  			rst := model.BlockInfo{}
    56  			return utils.CLIQueryJSONPrint(cdc, uri, nil,
    57  				func() interface{} { return &rst })
    58  		},
    59  	}
    60  }
    61  
    62  // GetCmdApp -
    63  func getCmdApp(cdc *codec.Codec) *cobra.Command {
    64  	return &cobra.Command{
    65  		Use:   "app",
    66  		Short: "app <app>",
    67  		Args:  cobra.ExactArgs(1),
    68  		RunE: func(cmd *cobra.Command, args []string) error {
    69  			app := args[0]
    70  			uri := fmt.Sprintf("custom/%s/%s/%s",
    71  				types.QuerierRoute, types.QueryAppBandwidthInfo, app)
    72  			rst := model.AppBandwidthInfo{}
    73  			return utils.CLIQueryJSONPrint(cdc, uri, nil,
    74  				func() interface{} { return &rst })
    75  		},
    76  	}
    77  }