2018-02-22 07:17:19 -08:00
|
|
|
package keys
|
|
|
|
|
2018-02-28 23:16:54 -08:00
|
|
|
import (
|
2019-06-08 03:04:52 -07:00
|
|
|
"github.com/spf13/cobra"
|
2020-07-06 12:50:09 -07:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2019-07-22 08:26:42 -07:00
|
|
|
|
2020-10-08 10:41:35 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2018-02-28 23:16:54 -08:00
|
|
|
)
|
|
|
|
|
2019-12-05 07:07:29 -08:00
|
|
|
const flagListNames = "list-names"
|
|
|
|
|
2019-12-12 13:52:24 -08:00
|
|
|
// ListKeysCmd lists all keys in the key store.
|
|
|
|
func ListKeysCmd() *cobra.Command {
|
2019-03-13 10:36:52 -07:00
|
|
|
cmd := &cobra.Command{
|
2019-02-08 12:45:23 -08:00
|
|
|
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.`,
|
2019-02-08 12:45:23 -08:00
|
|
|
RunE: runListCmd,
|
|
|
|
}
|
2020-06-30 13:59:21 -07:00
|
|
|
|
2019-12-05 07:07:29 -08:00
|
|
|
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
|
2019-03-13 10:36:52 -07:00
|
|
|
return cmd
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
|
|
|
|
2019-12-05 07:07:29 -08:00
|
|
|
func runListCmd(cmd *cobra.Command, _ []string) error {
|
2020-12-14 14:09:51 -08:00
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-22 07:17:19 -08:00
|
|
|
|
2020-10-08 10:41:35 -07:00
|
|
|
infos, err := clientCtx.Keyring.List()
|
2019-12-05 07:07:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-30 07:54:01 -07:00
|
|
|
cmd.SetOut(cmd.OutOrStdout())
|
2020-07-06 12:50:09 -07:00
|
|
|
|
|
|
|
if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
|
|
|
|
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
|
|
|
printInfos(cmd.OutOrStdout(), infos, output)
|
2019-12-05 07:07:29 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, info := range infos {
|
|
|
|
cmd.Println(info.GetName())
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|
2019-12-05 07:07:29 -08:00
|
|
|
|
|
|
|
return nil
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|