-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (61 loc) · 1.28 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/foxboron/gandictl/api"
"github.com/spf13/cobra"
)
var (
GandiAPIKey = os.Getenv("GANDICTL")
)
var rootCmd = &cobra.Command{
Use: "gandictl",
Short: "Edit gandi stuff",
}
func listCmd(c *api.Client) *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "list",
Run: func(cmd *cobra.Command, args []string) {
ret := api.GetDomains(c)
for _, item := range ret {
fmt.Println(item.Fqdn)
}
},
}
}
func recordsCmd(c *api.Client) *cobra.Command {
return &cobra.Command{
Use: "records",
Short: "records",
Run: func(cmd *cobra.Command, args []string) {
ret := api.GetZonefile(c, args[0])
fmt.Println(string(ret))
},
}
}
func editCmd(c *api.Client) *cobra.Command {
return &cobra.Command{
Use: "edit",
Short: "edit",
Run: func(cmd *cobra.Command, args []string) {
ret := api.GetZonefile(c, args[0])
buf, err := TempFile(ret)
if err != nil {
log.Fatal(err)
}
resp := api.WriteZonefile(c, args[0], buf)
fmt.Println(api.NewSuccsessResponse(resp).Message)
},
}
}
func main() {
c := api.NewClient(GandiAPIKey)
rootCmd.AddCommand(listCmd(c))
rootCmd.AddCommand(editCmd(c))
rootCmd.AddCommand(recordsCmd(c))
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}