-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
101 lines (84 loc) · 2.8 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/mariusgrigoriu/kanban-stats/trello"
influxdb "github.com/influxdata/influxdb/client/v2"
)
type flags struct {
trelloKey, trelloToken, trelloBoardID, influxURL, influxDB, influxUser, influxPassword string
verbose, dryRun, version bool
}
func getCommandLineFlags() (flags flags) {
flag.StringVar(&flags.trelloKey, "trellokey", "", "Trello application key")
flag.StringVar(&flags.trelloToken, "trellotoken", "", "Trello access token")
flag.StringVar(&flags.trelloBoardID, "boardid", "", "Trello board ID")
flag.StringVar(&flags.influxURL, "influxurl", "http://localhost:8086", "http://host:port")
flag.StringVar(&flags.influxDB, "influxdb", "kanban", "Influx datbase name")
flag.StringVar(&flags.influxUser, "influxuser", "root", "Influx username")
flag.StringVar(&flags.influxPassword, "influxpass", "root", "Influx password")
flag.BoolVar(&flags.verbose, "v", false, "Print verbose information")
flag.BoolVar(&flags.dryRun, "d", false, "Dry run does not output to database")
flag.BoolVar(&flags.version, "version", false, "Print version and exit")
flag.Parse()
return
}
func main() {
flags := getCommandLineFlags()
if flags.version {
fmt.Println(GetVersion())
return
}
if flags.trelloKey == "" {
flags.trelloKey = os.Getenv("TRELLO_KEY")
}
if flags.trelloToken == "" {
flags.trelloToken = os.Getenv("TRELLO_TOKEN")
}
if flags.influxPassword == "" {
flags.influxPassword = os.Getenv("INFLUX_PASS")
}
log.Print(ApplicationName, ": start")
defer log.Print(ApplicationName, ": end")
trello := trello.NetworkClient{
Key: flags.trelloKey,
Token: flags.trelloToken,
}
board := GetBoardFromTrello(trello, flags.trelloBoardID)
if flags.verbose {
printInfo(board)
}
if !flags.dryRun {
influxdb, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: flags.influxURL,
Username: flags.influxUser,
Password: flags.influxPassword,
})
if err != nil {
log.Fatal(ApplicationName, ": influxdb.NewClient: ", err)
}
err = writePointsToDatabase(influxdb, BuildPointBatch(flags.influxDB, board))
if err != nil {
log.Fatal(ApplicationName, ": writeStatsToDatabase: ", err)
}
//writeListsToDatabase(influxdbClient, board.Columns, flags.trelloBoardID)
}
}
func printInfo(board Board) {
fmt.Printf("Board ID: %v\n\nLists\n", board.GetID())
labelsFound := make(map[string]string, 1000)
for _, column := range board.GetColumns() {
fmt.Printf("%s(%s): %d\n", column.GetName(), column.GetID(), len(column.GetCards()))
for _, card := range column.GetCards() {
for _, label := range card.Labels {
labelsFound[label.Name] = label.ID
}
}
}
fmt.Printf("\nLabels In Use\n")
for name, id := range labelsFound {
fmt.Printf("%s: %s\n", name, id)
}
}