aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/app.go
diff options
context:
space:
mode:
Diffstat (limited to 'todolist/app.go')
-rw-r--r--todolist/app.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/todolist/app.go b/todolist/app.go
index 3235f99..6122b6a 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -1,5 +1,7 @@
package todolist
+import "regexp"
+
type App struct {
TodoStore Store
}
@@ -11,6 +13,26 @@ func NewApp() *App {
}
func (a *App) ListTodos(input string) {
- formatter := NewFormatter(a.TodoStore.Todos())
+
+ 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
+}