-
Notifications
You must be signed in to change notification settings - Fork 75
/
remove.go
44 lines (36 loc) · 1008 Bytes
/
remove.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
package sshkey
import (
"errors"
"fmt"
"strings"
"github.com/cnrancher/autok3s/pkg/common"
"github.com/cnrancher/autok3s/pkg/utils"
"github.com/spf13/cobra"
)
var removeCmd = &cobra.Command{
Use: "remove <name> [name...]",
Aliases: []string{"rm"},
Short: "Remove a stored ssh key pair.",
Args: cobra.MinimumNArgs(1),
Run: utils.CommandExitWithoutHelpInfo(remove),
}
func init() {
removeCmd.Flags().BoolVarP(&sshKeyFlags.isForce, "force", "f", false, "Force to delete a package.")
}
func remove(cmd *cobra.Command, args []string) error {
if !sshKeyFlags.isForce {
if !utils.IsTerm() {
return errors.New("please using --force to delete a ssh key pair")
}
if !utils.AskForConfirmation(fmt.Sprintf("are you going to remove ssh key pair(s) %s", strings.Join(args, ",")), false) {
return nil
}
}
for _, name := range args {
if err := common.DefaultDB.DeleteSSHKey(name); err != nil {
return err
}
cmd.Printf("ssh key %s removed\n", name)
}
return nil
}