-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
101 lines (89 loc) · 2.84 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cli
import (
"fmt"
"github.com/akhilkumarpilli/sdk-tutorial/x/orgstore/internal/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/spf13/cobra"
)
func GetQueryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
orgstoreQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the orgstore module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
orgstoreQueryCmd.AddCommand(client.GetCommands(
GetCmdUsers(storeKey, cdc),
GetCmdOrgData(storeKey, cdc),
GetCmdOrgs(storeKey, cdc),
)...)
return orgstoreQueryCmd
}
// GetCmdUsers queries information about users
func GetCmdUsers(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "org_users [name]",
Short: "Users of org",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
name := args[0]
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/org_users/%s", queryRoute, name), nil)
if err != nil {
fmt.Printf("could not find organisation - %s \n", name)
return nil
}
fmt.Printf(string(res))
//var out types.OrgUserList
//cdc.MustUnmarshalJSON(res, &out)
////p := types.{Response: out}
return cliCtx.PrintOutput(nil)
},
}
}
// GetCmdOrgData queries information about org data
func GetCmdOrgData(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "org_data [name]",
Short: "Query data of org",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
name := args[0]
fmt.Printf("Hello org %s", name)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/org_data/%s", queryRoute, name), nil)
if err != nil {
fmt.Printf("could not get data - %s \n", name)
return nil
}
fmt.Printf(string(res))
//var out types.Org
//cdc.MustUnmarshalJSON(res, &out)
//fmt.Println("Out",out)
////p := types.Printer{Response: out}
return cliCtx.PrintOutput(nil)
},
}
}
// GetCmdOrgs queries a list of all orgs
func GetCmdOrgs(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "orgs_list",
Short: "Org List",
// Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/org_list", queryRoute), nil)
if err != nil {
fmt.Printf("could not get query names\n")
return nil
}
var out types.QueryResOrgs
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}