cosmos-sdk/x/params/client/cli/query.go
Aaron Craelius 7de8ef75b3
Require proto.Message in client.Context.PrintOutput (#6999)
* Enable proto JSON json for cli tx & query

* WIP on tests

* Test fixes, cleanup

* Cleanup

* Address review comments

* Update client/context.go

Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>

* Fixes

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
2020-08-11 03:19:49 -04:00

58 lines
1.5 KiB
Go

package cli
import (
"context"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
)
// NewQueryCmd returns a root CLI command handler for all x/params query commands.
func NewQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the params module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(NewQuerySubspaceParamsCmd())
return cmd
}
// NewQuerySubspaceParamsCmd returns a CLI command handler for querying subspace
// parameters managed by the x/params module.
func NewQuerySubspaceParamsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "subspace [subspace] [key]",
Short: "Query for raw parameters by subspace and key",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := proposal.NewQueryClient(clientCtx)
params := proposal.QueryParamsRequest{Subspace: args[0], Key: args[1]}
res, err := queryClient.Params(context.Background(), &params)
if err != nil {
return err
}
return clientCtx.PrintOutput(&res.Param)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}