This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (68 loc) · 1.72 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"log"
"github.com/c0rby/todo/todolib"
cfg "github.com/c0rby/todo/todolib/config"
"github.com/docopt/docopt-go"
)
const configPath = ".config/todo/config.json"
var (
config *cfg.Config
todo *todolib.Todo
)
func init() {
config = cfg.Load(configPath)
todo = todolib.New(*config)
if !todo.BaseDirExists() {
todo.CreateBaseDir()
}
}
func main() {
usage := `
Usage:
todo (<folder> ls| ls)
todo mkdir <folder>
todo rm <folder>
todo (<folder> head | head)
todo (<folder> cat [<name>] | cat [<name>])
todo (<folder> <todo> | <todo>)
todo (<folder> (-d | --done) <todo>| (-d | --done) <todo>)
todo (<folder> (-u | --undo) <todo>| (-u | --undo) <todo>)
todo -h | --help
todo --version
`
arguments, err := docopt.Parse(usage, nil, true, "todo 0.1", false)
if err != nil {
log.Fatal("uh oh" + err.Error())
}
var folder string
if arguments["<folder>"] != nil {
folder = arguments["<folder>"].(string)
}
if arguments["ls"] == true {
todo.ListFiles(folder)
} else if arguments["mkdir"] == true {
todo.MakeDir(arguments["<folder>"].(string))
} else if arguments["rm"] == true {
todo.RemoveDir(arguments["<folder>"].(string))
} else if arguments["<todo>"] != nil {
t := arguments["<todo>"].(string)
if arguments["-d"] == true || arguments["--done"] == true {
todo.Complete(folder, t)
return
} else if arguments["-u"] == true || arguments["--undo"] == true {
todo.Undo(folder, t)
return
}
todo.Add(folder, t)
} else if arguments["cat"] == true {
if arguments["<name>"] == nil {
todo.ReadCurrent(folder)
} else {
todo.Read(folder, arguments["<name>"].(string))
}
} else if arguments["head"] == true {
todo.ReadLinesCurrent(folder, 5)
}
//fmt.Println(arguments)
}