-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
53 lines (50 loc) · 1.13 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
package main
import (
"fmt"
"os"
"github.com/merschformann/gotz/core"
)
func main() {
// Get configuration
config, err := core.Load()
// If there was an error loading the config, offer the user the option to
// reset it (or simply exit).
if err != nil {
fmt.Println("error loading configuration:", err)
// Ask the user if they want to reset the config
if ok, in_err := core.AskUser("Reset configuration?"); in_err != nil {
fmt.Println("error asking user:", in_err)
os.Exit(1)
} else if ok {
// Reset config
config, in_err = core.SaveDefault()
if in_err != nil {
fmt.Println("error resetting configuration:", in_err)
os.Exit(1)
}
} else {
// Exit
os.Exit(0)
}
}
// Parse flags
config, rt, changed, err := core.ParseFlags(config, Version)
if err != nil {
fmt.Println("error parsing flags:", err)
os.Exit(1)
}
// Update config, if necessary
if changed {
err = config.Save()
if err != nil {
fmt.Println("error saving configuration update:", err)
os.Exit(1)
}
}
// Plot time
err = core.Plot(config, rt)
if err != nil {
fmt.Println("error plotting time:", err)
os.Exit(1)
}
}