-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (41 loc) · 1.15 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
package main
import (
"encoding/json"
"fmt"
"github.com/achenet/TimeLog/cmd"
"github.com/achenet/TimeLog/data_store"
"os"
)
func main() {
// Set storage file path
cmd.SetStorageFilePath()
// Make storage directory if it isn't already created
if err := os.MkdirAll(cmd.StorageDirectory, 744); err != nil {
fmt.Println("Error making storage directory: \n", err.Error())
os.Exit(1)
}
// Create datastore file if it doesn't already exist
_, err := os.Open(cmd.StorageFilePath)
if err != nil {
fmt.Println("Could not open file, due to", err.Error(), "\nOpting to create one instead.")
file, err := os.Create(cmd.StorageFilePath)
if err != nil {
fmt.Println("Could not create storage file:\n" + err.Error())
os.Exit(1)
}
// If it doesn't exist, write something empty in it.
tl := make(data_store.DataStore)
m, err := json.Marshal(tl)
if err != nil {
fmt.Println("Error creating blank file:\n" + err.Error())
os.Exit(1)
}
_, err = file.Write(m)
if err != nil {
fmt.Println("Error writing empty datastore to new file:\n" + err.Error())
os.Exit(1)
}
fmt.Println("Created and wrote to empty file")
}
cmd.Execute()
}