-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
list.go
70 lines (57 loc) · 1.57 KB
/
list.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
package keys
import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
)
const flagListNames = "list-names"
// ListKeysCmd lists all keys in the key store.
func ListKeysCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all keys",
Long: `Return a list of all public keys stored by this key manager
along with their associated name and address.`,
RunE: runListCmd,
}
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
return cmd
}
func runListCmd(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
records, err := clientCtx.Keyring.List()
if err != nil {
return err
}
if len(records) == 0 && clientCtx.OutputFormat == OutputFormatJSON {
cmd.Println("No records were found in keyring")
return nil
}
if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
return printKeyringRecords(cmd.OutOrStdout(), records, clientCtx.OutputFormat)
}
for _, k := range records {
cmd.Println(k.Name)
}
return nil
}
// ListKeyTypesCmd lists all key types.
func ListKeyTypesCmd() *cobra.Command {
return &cobra.Command{
Use: "list-key-types",
Short: "List all key types",
Long: `Return a list of all supported key types (also known as algos)`,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
cmd.Println("Supported key types/algos:")
keyring, _ := clientCtx.Keyring.SupportedAlgorithms()
cmd.Printf("%+q\n", keyring)
return nil
},
}
}