-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
102 lines (88 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/codegangsta/cli"
"github.com/gutengo/fil"
"github.com/gutengo/shell"
"os"
)
var pd = fmt.Println
type Rc struct {
ACCESS_KEY_ID string
ACCESS_KEY_SECRET string
}
var rc Rc
func main() {
cli.AppHelpTemplate = `{{.Name}} v{{.Version}} - {{.Usage}}
USAGE:
{{.Name}} {{if .Flags}}[options] {{end}}<command> [arguments]
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
app := cli.NewApp()
app.Name = "aliyundns"
app.Usage = "list and update dns record"
app.Version = "0.0.1"
app.Action = func(c *cli.Context) {
cli.ShowAppHelp(c)
}
app.Commands = []cli.Command{
{
Name: "list",
Usage: "<domain>",
Action: func(c *cli.Context) {
pd(getIp())
/*
args := c.Args()
if len(args) < 1 {
shell.ErrorExit("Missing domain argument.\n\nExample:\n\n $ aliyundns list example.com")
}
List(args.Get(0))
*/
},
},
{
Name: "update",
Usage: "<record_id> <rr> <value>",
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 3 {
shell.ErrorExit("Must provide 3 arguments.\n\nExample:\n\n $ aliyundns update 1234567 www 192.168.1.1")
}
err := Update(args.Get(0), args.Get(1), args.Get(2))
if err != nil {
shell.ErrorExit(err)
}
fmt.Println("Success")
},
},
{
Name: "server",
Usage: "<port>",
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 1 {
shell.ErrorExit("Must provide 2 arguments.\n\nExample:\n\n $ aliyundns server 3000")
}
Server(args.Get(0))
},
},
}
rc = loadRc()
app.Run(os.Args)
}
func loadRc() (ret Rc) {
file := os.Getenv("HOME") + "/.aliyundnsrc"
if ok, _ := fil.IsNotExist(file); ok {
return Rc{}
}
if _, err := toml.DecodeFile(file, &ret); err != nil {
shell.ErrorExit("%s: %s\n", "Load "+file, err)
}
return ret
}