blob: 00effa7a6644e620717403251dc0b29d206447fc (
plain)
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
|
package todolist
import (
"fmt"
"regexp"
)
type App struct {
TodoStore Store
}
func NewApp() *App {
app := &App{TodoStore: NewFileStore()}
app.TodoStore.Load()
return app
}
func (a *App) AddTodo(input string) {
parser := &Parser{}
todo := parser.Parse(input)
a.TodoStore.Add(todo)
a.TodoStore.Save()
fmt.Println("Todo added.")
}
func (a *App) ListTodos(input string) {
//filtered := NewFilter(a.TodoStore.Todos()).filter()
grouped := a.getGroups(input)
formatter := NewFormatter(grouped)
formatter.Print()
}
func (a *App) getGroups(input string) *GroupedTodos {
grouper := &Grouper{}
contextRegex, _ := regexp.Compile(`by c.*$`)
projectRegex, _ := regexp.Compile(`by p.*$`)
var grouped *GroupedTodos
if contextRegex.MatchString(input) {
grouped = grouper.GroupByContext(a.TodoStore.Todos())
} else if projectRegex.MatchString(input) {
grouped = grouper.GroupByContext(a.TodoStore.Todos())
} else {
grouped = grouper.GroupByNothing(a.TodoStore.Todos())
}
return grouped
}
|