-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
54 lines (44 loc) · 1.08 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
package main
import (
"log"
"os"
"github.com/dmurray-lacework/tally-git/api"
"github.com/dmurray-lacework/tally-git/config"
"github.com/olekukonko/tablewriter"
"github.com/spf13/viper"
)
var configuration config.Configuration
func main() {
client, err := api.NewClient(configuration.Github.Apikey)
if err != nil {
os.Exit(1)
}
repos := client.Github.GetRepos()
outputTable([]string{"Repository", "Issues", "Pull Requests"}, tableFormat(repos))
}
func init() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Error reading config file, %s", err)
}
err := viper.Unmarshal(&configuration)
if err != nil {
log.Fatalf("unable to decode into struct, %v", err)
}
}
func tableFormat(repos []api.RepoResponse) [][]string {
data := [][]string{}
for _, r := range repos {
data = append(data, r.ToArray())
}
return data
}
func outputTable(headers []string, data [][]string) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(headers)
for _, v := range data {
table.Append(v)
}
table.Render()
}