/
query.go
61 lines (51 loc) · 1.49 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cli
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/irisnet/irishub/v2/modules/guardian/types"
)
// GetQueryCmd returns the cli query commands for the guardian module.
func GetQueryCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the guardian module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
GetCmdQuerySupers(),
)
return txCmd
}
// GetCmdQuerySupers implements the query supers command.
func GetCmdQuerySupers() *cobra.Command {
cmd := &cobra.Command{
Use: "supers",
Short: "Query for all supers",
Example: fmt.Sprintf("%s query guardian supers", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
res, err := queryClient.Supers(context.Background(), &types.QuerySupersRequest{Pagination: pageReq})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "all supper")
return cmd
}