-
Notifications
You must be signed in to change notification settings - Fork 9
/
factorialsucks.go
113 lines (106 loc) · 2.54 KB
/
factorialsucks.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
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"log"
"os"
"time"
"github.com/alejoar/factorialsucks/factorial"
"github.com/urfave/cli/v2"
)
var today time.Time = time.Now()
func main() {
log.SetFlags(0)
app := &cli.App{
Name: "factorialsucks",
Usage: "FactorialHR auto clock in for the whole month from the command line",
Version: "2.1",
Compiled: time.Now(),
UsageText: "factorialsucks [options]",
HideHelpCommand: true,
HideVersion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "email",
Aliases: []string{"e"},
Usage: "you factorial email address",
},
&cli.IntFlag{
Name: "year",
Aliases: []string{"y"},
Usage: "clock-in year `YYYY`",
DefaultText: "current year",
Value: today.Year(),
},
&cli.IntFlag{
Name: "month",
Aliases: []string{"m"},
Usage: "clock-in month `MM`",
DefaultText: "current month",
Value: int(today.Month()),
},
&cli.StringFlag{
Name: "clock-in",
Aliases: []string{"ci"},
Usage: "clock-in time `HH:MM`",
Value: "10:00",
},
&cli.StringFlag{
Name: "clock-out",
Aliases: []string{"co"},
Usage: "clock-in time `HH:MM`",
Value: "18:00",
},
&cli.BoolFlag{
Name: "today",
Aliases: []string{"t"},
Usage: "clock in for today only",
Value: false,
},
&cli.BoolFlag{
Name: "until-today",
Aliases: []string{"ut"},
Usage: "clock in only until today",
Value: false,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"dr"},
Usage: "do a dry run without actually clocking in",
},
&cli.BoolFlag{
Name: "reset-month",
Aliases: []string{"rm"},
Usage: "delete all shifts for the given month",
Value: false,
},
},
Action: factorialsucks,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func factorialsucks(c *cli.Context) error {
var year, month int
email, password := readCredentials(c)
today_only := c.Bool("today")
if today_only {
year = today.Year()
month = int(today.Month())
} else {
year = c.Int("year")
month = c.Int("month")
}
clock_in := c.String("clock-in")
clock_out := c.String("clock-out")
dry_run := c.Bool("dry-run")
until_today := c.Bool("until-today")
reset_month := c.Bool("reset-month")
client := factorial.NewFactorialClient(email, password, year, month, clock_in, clock_out, today_only, until_today)
if reset_month {
client.ResetMonth()
} else {
client.ClockIn(dry_run)
}
return nil
}