-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtogglo.go
80 lines (74 loc) · 2.02 KB
/
togglo.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
package main
import (
"github.com/codegangsta/cli"
"os"
"time"
)
func main() {
app := cli.NewApp()
app.Name = "togglo"
app.Usage = "Compile toggle from command-line"
app.Version = "1.0.0"
configuration := getConfiguration()
app.Commands = []cli.Command{
{
Name: "work",
Usage: "Add a ordinary work day time entry",
Action: func(c *cli.Context) {
if len(c.Args()) < 2 {
println("Usage: togglo work [project_id] [date]")
println("Example: togglo work 9324358 2014-12-31")
os.Exit(1)
}
var projectId = c.Args()[0]
var date = c.Args()[1]
addOrdinaryWorkDay(configuration.WorkspaceId, projectId, date)
},
},
{
Name: "vacation",
Usage: "Add a vacation day time entry",
Action: func(c *cli.Context) {
if len(c.Args()) < 1 {
println("Usage: togglo vacation [date]")
println("Example: togglo vacation 2014-12-31")
os.Exit(1)
}
var date = c.Args()[0]
addVacationDay(configuration.WorkspaceId, date)
},
},
{
Name: "projects",
Usage: "List of all projects in you workspace",
Action: func(c *cli.Context) {
for _, project := range getProjects() {
println(project.Id, " : ", project.Name)
}
},
},
}
app.Run(os.Args)
}
func addOrdinaryWorkDay(workspaceId, projectId, date string) {
midnightDate := parseDate(date)
entries := createDayTimeEntries(workspaceId, projectId, midnightDate, []string{})
sendTimeEntries(entries)
}
func addVacationDay(workspaceId, date string) {
midnightDate := parseDate(date)
vacationProjectId := "8352044"
entries := createDayTimeEntries(workspaceId, vacationProjectId, midnightDate, []string{"Ferie"})
sendTimeEntries(entries)
}
func parseDate(date string) time.Time {
timezone, _ := time.LoadLocation("Europe/Rome")
exampleFormat := "2006-01-02"
midnightDate, errorDateFormat := time.ParseInLocation(exampleFormat, date, timezone)
if errorDateFormat != nil {
println("ERROR: Date format should be: ", exampleFormat)
println(errorDateFormat.Error())
os.Exit(1)
}
return midnightDate
}