-
Notifications
You must be signed in to change notification settings - Fork 0
/
10chapters.go
43 lines (36 loc) · 1.09 KB
/
10chapters.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
package main
import (
"flag"
"fmt"
"os"
"text/template"
"time"
)
func main() {
var currentDay, daysAdvanced, daysSkipped int
var dateStarted string
var runHttpd bool
flag.BoolVar(&runHttpd, "httpd", false, "Whether to start http server on port 8080")
flag.StringVar(&dateStarted, "date-started", time.Now().Format("2006-01-02"),
"The date you started reading this plan.")
flag.IntVar(&daysAdvanced, "days-advanced", 0, "Amount of days you read in advance.")
flag.IntVar(&daysSkipped, "days-skipped", 0, "Amount of days you skipped the reading.")
flag.IntVar(¤tDay, "day", 1, "Current day you are reading.")
flag.Parse()
lists := generateLists()
chapters := generateListChapters(lists)
if runHttpd {
serve(chapters)
return
}
currentDay, err := decidePrintDay(currentDay,
dateStarted, daysAdvanced, daysSkipped)
if err != nil {
fmt.Println("Couldn’t select a day to use, due to this error:")
fmt.Println(err)
return
}
tmpl := template.Must(template.ParseFiles("tmpl/cli.txt"))
tmplData := prepareTmplData(currentDay, chapters)
tmpl.Execute(os.Stdout, tmplData)
}