-
Notifications
You must be signed in to change notification settings - Fork 0
/
standings.go
51 lines (37 loc) · 983 Bytes
/
standings.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
package main
import (
"github.com/urfave/cli"
"fmt"
"os"
"encoding/json"
"github.com/olekukonko/tablewriter"
"strconv"
)
func ListStandings(c *cli.Context) {
results := APIResponse{}
res, err := GetJson(API.GetStandings)
if err != nil {
fmt.Println("Something went wrong : " + err.Error())
os.Exit(2)
}
err = json.Unmarshal(res, &results)
if err != nil {
fmt.Println("Something went wrong : " + err.Error())
os.Exit(2)
}
for _, group := range results.Groups {
table := tablewriter.NewWriter(c.App.Writer)
table.SetHeader([]string{group.Name, "P", "W", "D", "L", "GF", "GA", "PTS"})
for _, standing := range group.Standings {
table.Append([]string{standing.Team.Name,
strconv.Itoa(standing.Played),
strconv.Itoa(standing.Won),
strconv.Itoa(standing.Drawn),
strconv.Itoa(standing.Lost),
strconv.Itoa(standing.GoalsFor),
strconv.Itoa(standing.GoalsAgainst),
strconv.Itoa(standing.Pts)})
}
table.Render()
}
}