-
Notifications
You must be signed in to change notification settings - Fork 18
/
dns_remove.go
57 lines (46 loc) · 1.14 KB
/
dns_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
45
46
47
48
49
50
51
52
53
54
55
56
57
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// dnsRemoveCmd represents the remove command
var dnsRemoveCmd = &cobra.Command{
Use: "remove <domain name> <record name | id>",
Short: "Remove a domain record",
Aliases: gRemoveAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return cmd.Usage()
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
if !force {
if !askQuestion(fmt.Sprintf("Are you sure you want to remove %q record", args[1])) {
return nil
}
}
if _, err = removeRecord(args[0], args[1]); err != nil {
return err
}
if !gQuiet {
fmt.Printf("Record %q removed successfully from %q\n", args[1], args[0])
}
return nil
},
}
func removeRecord(domainName, record string) (int64, error) {
id, err := getRecordIDByName(domainName, record)
if err != nil {
return 0, err
}
if err := csDNS.DeleteRecord(gContext, domainName, id); err != nil {
return 0, err
}
return id, nil
}
func init() {
dnsCmd.AddCommand(dnsRemoveCmd)
dnsRemoveCmd.Flags().BoolP("force", "f", false, "Attempt to remove without prompting for confirmation")
}