From c4d6dbdb100bb66db9b184c653617c47a63e91ca Mon Sep 17 00:00:00 2001 From: Quey-Liang Kao Date: Mon, 14 Aug 2017 16:12:53 +0800 Subject: Implement the "dn" feature: Deleteing notes --- todolist/parser.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'todolist/parser.go') 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") -- cgit v1.3