-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
97 lines (83 loc) · 1.5 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
package main
import (
"errors"
"log"
"os"
"strings"
"github.com/blizztrack/ribbit-go"
"github.com/sanity-io/litter"
"github.com/urfave/cli"
)
var (
region string
)
func process(c *cli.Context) error {
var game string
var mode string
if len(c.Args()) == 0 {
cli.ShowAppHelp(c)
return nil
}
if len(c.Args()) > 1 {
mode = strings.ToLower(c.Args()[1])
game = strings.ToLower(c.Args()[0])
} else {
game = strings.ToLower(c.Args()[0])
}
client := ribbit.NewRibbitClient(region)
if game == "summary" {
summary, err := client.Summary()
if err != nil {
return err
}
litter.Dump(summary)
return nil
}
var res interface{}
switch mode {
case "versions":
vers, err := client.Versions(game)
if err != nil {
return err
}
res = vers
break
case "bgdl":
vers, err := client.BGDL(game)
if err != nil {
return err
}
res = vers
break
case "cdns":
vers, err := client.CDNS(game)
if err != nil {
return err
}
res = vers
break
default:
return errors.New("supported modes: versions, bgdl, cdns")
}
litter.Dump(res)
return nil
}
func main() {
app := cli.NewApp()
app.Name = "Ribbit Cli Client"
app.Description = "Cli Client for access Battle.net Ribbit services"
app.HideVersion = true
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "region, r",
Value: "us",
Usage: "Region to use: us, eu, kr, sg, cn",
Destination: ®ion,
},
}
app.Action = process
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}