-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
50 lines (41 loc) · 1.2 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
package keys
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/client/flags"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/crypto/keys"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
)
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().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
return cmd
}
func runListCmd(cmd *cobra.Command, _ []string) error {
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
if err != nil {
return err
}
infos, err := kb.List()
if err != nil {
return err
}
if !viper.GetBool(flagListNames) {
printInfos(infos)
return nil
}
cmd.SetOut(cmd.OutOrStdout())
for _, info := range infos {
cmd.Println(info.GetName())
}
return nil
}