package cli
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/joinresistance/space-pussy/x/dmn/types"
)
func GetQueryCmd() *cobra.Command {
DmnQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
DmnQueryCmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryThought(),
GetCmdQueryThoughtStats(),
GetCmdQueryThoughts(),
GetCmdQueryThoughtsStats(),
)
return DmnQueryCmd
}
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
Short: "Query the current dmn module parameters information",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func GetCmdQueryThought() *cobra.Command {
cmd := &cobra.Command{
Use: "thought [program] [name]",
Short: "Query thought",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
program, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
res, err := queryClient.Thought(
context.Background(),
&types.QueryThoughtParamsRequest{
program.String(), args[1],
},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func GetCmdQueryThoughtStats() *cobra.Command {
cmd := &cobra.Command{
Use: "thought-stats [program] [name]",
Short: "Query thought stats",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
program, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
res, err := queryClient.ThoughtStats(
context.Background(),
&types.QueryThoughtParamsRequest{
program.String(), args[1],
},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func GetCmdQueryThoughts() *cobra.Command {
cmd := &cobra.Command{
Use: "thoughts",
Short: "Query all thoughts",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Thoughts(
context.Background(),
&types.QueryThoughtsRequest{},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func GetCmdQueryThoughtsStats() *cobra.Command {
cmd := &cobra.Command{
Use: "thoughts-stats",
Short: "Query all thoughts stats",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.ThoughtsStats(
context.Background(),
&types.QueryThoughtsStatsRequest{},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}