cosmos-sdk/client/keys/list.go

48 lines
1008 B
Go
Raw Normal View History

2018-02-22 07:17:19 -08:00
package keys
import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
2020-10-08 10:41:35 -07:00
"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
2018-02-22 07:17:19 -08:00
along with their associated name and address.`,
RunE: runListCmd,
}
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
return cmd
2018-02-22 07:17:19 -08:00
}
func runListCmd(cmd *cobra.Command, _ []string) error {
2020-10-08 10:41:35 -07:00
clientCtx := client.GetClientContextFromCmd(cmd)
2018-02-22 07:17:19 -08:00
2020-10-08 10:41:35 -07:00
infos, err := clientCtx.Keyring.List()
if err != nil {
return err
}
cmd.SetOut(cmd.OutOrStdout())
if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
output, _ := cmd.Flags().GetString(cli.OutputFlag)
printInfos(cmd.OutOrStdout(), infos, output)
return nil
}
for _, info := range infos {
cmd.Println(info.GetName())
2018-02-22 07:17:19 -08:00
}
return nil
2018-02-22 07:17:19 -08:00
}