-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
delete.go
71 lines (58 loc) · 1.82 KB
/
delete.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
package keys
import (
"bufio"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
)
const (
flagYes = "yes"
flagForce = "force"
)
// DeleteKeyCommand deletes a key from the key store.
func DeleteKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <name>...",
Short: "Delete the given keys",
Long: `Delete keys from the Keybase backend.
Note that removing offline or ledger keys will remove
only the public key references stored locally, i.e.
private keys stored in a ledger device cannot be deleted with the CLI.
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
for _, name := range args {
info, err := clientCtx.Keyring.Key(name)
if err != nil {
return err
}
// confirm deletion, unless -y is passed
if skip, _ := cmd.Flags().GetBool(flagYes); !skip {
if yes, err := input.GetConfirmation("Key reference will be deleted. Continue?", buf, cmd.ErrOrStderr()); err != nil {
return err
} else if !yes {
continue
}
}
if err := clientCtx.Keyring.Delete(name); err != nil {
return err
}
if info.GetType() == keyring.TypeLedger || info.GetType() == keyring.TypeOffline {
cmd.PrintErrln("Public key reference deleted")
continue
}
cmd.PrintErrln("Key deleted forever (uh oh!)")
}
return nil
},
}
cmd.Flags().BoolP(flagYes, "y", false, "Skip confirmation prompt when deleting offline or ledger key references")
cmd.Flags().BoolP(flagForce, "f", false, "Remove the key unconditionally without asking for the passphrase. Deprecated.")
return cmd
}