diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-14 16:12:53 +0800 |
|---|---|---|
| committer | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-14 16:12:53 +0800 |
| commit | c4d6dbdb100bb66db9b184c653617c47a63e91ca (patch) | |
| tree | 73555a8af7496a5af47b9257037fd327fe7a279f | |
| parent | 26ec23620d50be79ea664a9095b3653be79e3874 (diff) | |
Implement the "dn" feature: Deleteing notes
| -rw-r--r-- | todo.go | 4 | ||||
| -rw-r--r-- | todolist/parser.go | 17 | ||||
| -rw-r--r-- | todolist/parser_test.go | 7 |
3 files changed, 27 insertions, 1 deletions
@@ -127,6 +127,8 @@ func usage() { fmt.Println("\tAdds notes \"check http://this.web.site\" to the todo with id 12\n") yellow.Println("\ttodo ln 12") fmt.Println("\tLists notes of the todo with id 12\n") + yellow.Println("\ttodo dn 12 3") + fmt.Println("\tDeletes the 3rd note of the todo with id 12\n") blueBold.Println("\nGarbage Collection") yellow.Println("\ttodo gc") @@ -159,7 +161,7 @@ func routeInput(command string, input string) { app.EditTodo(input) case "ex", "expand": app.ExpandTodo(input) - case "an", "ln": + case "an", "ln", "dn": app.ManipulateNotes(input) case "gc": app.GarbageCollect() diff --git a/todolist/parser.go b/todolist/parser.go index 1c3b7f8..3883454 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -90,12 +90,29 @@ func (p *Parser) ParseNotes(todo *Todo, input string) string { case "an": todo.Notes = append(todo.Notes, matches[2]) return "add" + case "ln": groups := map[string][]*Todo{} groups[""] = append(groups[""], todo) formatter := NewFormatter(&GroupedTodos{Groups: groups}) formatter.PrintNotes() return "list" + + case "dn": + rmid, err := strconv.Atoi(matches[2]) + if err != nil { + fmt.Println("wrong note id") + return "" + } + + for id, _ := range todo.Notes { + if id == rmid { + todo.Notes = append(todo.Notes[:rmid], todo.Notes[rmid+1:]...) + return "delete" + } + } + fmt.Println("Could not found note id") + return "" } fmt.Println("Could not match command or id") diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 9412bdf..e5c7007 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -84,6 +84,13 @@ func TestParseNotes(t *testing.T) { if todo.Notes[0] != "www.google.com" { t.Error("Expected note 1 to be 'www.google.com' but got", todo.Notes[0]) } + + if parser.ParseNotes(todo, "dn 1 0") != "delete" { + t.Error("Expected Notes to be deleted") + } + if len(todo.Notes) != 0 { + t.Error("Expected no note") + } } func TestDueToday(t *testing.T) { |
