This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
dns.go
77 lines (69 loc) · 1.53 KB
/
dns.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
72
73
74
75
76
77
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var DNS = &cobra.Command{
Use: "dns",
}
var domain string
func init() {
append := &cobra.Command{
Use: "append",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
dns := getPlatform(cmd).GetDNSClient()
if err := dns.Append(domain, args...); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
update := &cobra.Command{
Use: "update",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
dns := getPlatform(cmd).GetDNSClient()
if err := dns.Update(domain, args...); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
get := &cobra.Command{
Use: "get",
Args: cobra.MaximumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
dns := getPlatform(cmd).GetDNSClient()
list, err := dns.Get(domain)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, record := range list {
fmt.Println(record)
}
},
}
delete := &cobra.Command{
Use: "delete",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
dns := getPlatform(cmd).GetDNSClient()
if err := dns.Delete(domain, args...); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
DNS.AddCommand(append, update, delete, get)
DNS.PersistentFlags().StringVar(&domain, "domain", "", "")
DNS.PersistentPreRun = func(cmd *cobra.Command, args []string) {
if domain == "" {
fmt.Println("Must specify a --domain")
os.Exit(1)
}
}
_ = DNS.MarkFlagRequired("domain")
}