From 3f14a184e28927697185d35829fa1bdb9db5b80d Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Thu, 12 May 2016 07:18:47 -0400 Subject: Make agenda its own command --- todo.go | 6 +++--- todolist/date_filter.go | 8 ++++++-- todolist/parser_test.go | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/todo.go b/todo.go index 45d5425..7c87a38 100644 --- a/todo.go +++ b/todo.go @@ -42,7 +42,7 @@ func usage() { blueBold.Println("\nListing todos") fmt.Println(" When listing todos, you can filter and group the output.\n") - fmt.Println(" todo l due (agenda|tod|today|tom|tomorrow|overdue|this week|next week|mon|tue|wed|thu|fri|sat|sun|none)") + fmt.Println(" todo l due (tod|today|tom|tomorrow|overdue|this week|next week|mon|tue|wed|thu|fri|sat|sun|none)") fmt.Println(" todo l overdue") cyan.Println(" Filtering by date:\n") @@ -54,7 +54,7 @@ func usage() { fmt.Println("\tlists all todos due monday\n") yellow.Println("\ttodo l overdue") fmt.Println("\tlists all todos where the due date is in the past\n") - yellow.Println("\ttodo l agenda") + yellow.Println("\ttodo agenda") fmt.Println("\tlists all todos where the due date is today or in the past\n") cyan.Println(" Grouping:") @@ -104,7 +104,7 @@ func usage() { func routeInput(command string, input string) { app := todolist.NewApp() switch command { - case "l", "list": + case "l", "list", "agenda": app.ListTodos(input) case "a", "add": app.AddTodo(input) diff --git a/todolist/date_filter.go b/todolist/date_filter.go index f027dd9..404e0b1 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -1,6 +1,7 @@ package todolist import ( + "fmt" "regexp" "time" @@ -16,11 +17,14 @@ func NewDateFilter(todos []*Todo) *DateFilter { } func (f *DateFilter) FilterDate(input string) []*Todo { + if input == "agenda" { + fmt.Println("input IS agenda") + return f.filterAgenda(now.BeginningOfDay()) + } r, _ := regexp.Compile(`due .*$`) + match := r.FindString(input) switch { - case match == "agenda": - return f.filterAgenda(now.BeginningOfDay()) case match == "due tod" || match == "due today": return f.filterToday(now.BeginningOfDay()) case match == "due tom" || match == "due tomorrow": diff --git a/todolist/parser_test.go b/todolist/parser_test.go index e913437..44ce3f7 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -72,7 +72,6 @@ func TestDueTomorrow(t *testing.T) { func TestDueSpecific(t *testing.T) { assert := assert.New(t) parser := &Parser{} - fmt.Println("Parsing new todo") todo := parser.ParseNewTodo("do this thing with @bob and @mary due jun 1") assert.Equal("2016-06-01", todo.Due) } -- cgit v1.3