aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStuart Skelton <stuarts@broadbean.com>2017-09-27 19:13:04 +0100
committerStuart Skelton <stuarts@broadbean.com>2017-09-27 19:55:35 +0100
commitaac8a1f17beeb6069da999cde1fc20c251811318 (patch)
tree75749417869e43900195d3850c09045932674714
parentffb472f7d84952228dd244f4911806f0e6a31e77 (diff)
Implement a done option
-rw-r--r--todo.go2
-rw-r--r--todolist/app.go20
-rw-r--r--todolist/app_test.go16
3 files changed, 38 insertions, 0 deletions
diff --git a/todo.go b/todo.go
index 98bc133..d2cc06e 100644
--- a/todo.go
+++ b/todo.go
@@ -149,6 +149,8 @@ func routeInput(command string, input string) {
app.ListTodos(input)
case "a", "add":
app.AddTodo(input)
+ case "done":
+ app.AddDoneTodo(input)
case "d", "delete":
app.DeleteTodo(input)
case "c", "complete":
diff --git a/todolist/app.go b/todolist/app.go
index 92ee64d..24e2a61 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -36,6 +36,26 @@ func (a *App) AddTodo(input string) {
fmt.Printf("Todo %d added.\n", id)
}
+// AddDoneTodo Adds a todo and immediately completed it.
+func (a *App) AddDoneTodo(input string) {
+ a.Load()
+
+ r, _ := regexp.Compile(`^(done)(\s*|)`)
+ input = r.ReplaceAllString(input, "")
+ parser := &Parser{}
+ todo := parser.ParseNewTodo(input)
+ if todo == nil {
+ fmt.Println("I need more information. Try something like 'todo done chating with @bob'")
+ return
+ }
+
+ id := a.TodoList.NextId()
+ a.TodoList.Add(todo)
+ a.TodoList.Complete(id)
+ a.Save()
+ fmt.Printf("Completed Todo %d added.\n", id)
+}
+
func (a *App) DeleteTodo(input string) {
a.Load()
ids := a.getIds(input)
diff --git a/todolist/app_test.go b/todolist/app_test.go
index 360da43..f95987d 100644
--- a/todolist/app_test.go
+++ b/todolist/app_test.go
@@ -27,6 +27,22 @@ func TestAddTodo(t *testing.T) {
assert.Equal([]string{}, todo.Contexts)
}
+func TestAddDoneTodo(t *testing.T) {
+ assert := assert.New(t)
+ app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
+
+ app.AddDoneTodo("Groked how to do done todos @pop")
+
+ todo := app.TodoList.FindById(1)
+ assert.Equal("Groked how to do done todos @pop", todo.Subject)
+ assert.Equal(true, todo.Completed)
+ assert.Equal(false, todo.Archived)
+ assert.Equal(false, todo.IsPriority)
+ assert.Equal([]string{}, todo.Projects)
+ assert.Equal(1, len(todo.Contexts))
+ assert.Equal("pop", todo.Contexts[0])
+}
+
func TestAddTodoWithEuropeanDates(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}