-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgotd.go
More file actions
54 lines (48 loc) · 809 Bytes
/
gotd.go
File metadata and controls
54 lines (48 loc) · 809 Bytes
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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"github.com/ghigt/cli"
"github.com/ghigt/gotd/cmd"
)
func readFile() {
buf, err := ioutil.ReadFile(".datast")
if err == nil {
err = json.Unmarshal(buf, &cmd.Tasks)
if err != nil {
log.Fatal(err)
}
}
}
func saveInFile() {
b, err := json.Marshal(cmd.Tasks)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(".datast", b, 0640)
if err != nil {
log.Fatal(err)
}
}
func main() {
app := cli.NewApp()
app.Name = "gotd"
app.Version = "0.1"
app.Usage = "fight the laziness!"
app.Action = func(c *cli.Context) {
cli.ShowAppHelp(c)
}
app.Commands = []cli.Command{
cmd.CmdRun,
cmd.CmdList,
cmd.CmdAdd,
cmd.CmdRemove,
cmd.CmdEdit,
cmd.CmdReset,
}
readFile()
defer saveInFile()
app.Run(os.Args)
}