aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/app.go
diff options
context:
space:
mode:
authorQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-08-29 17:00:18 +0800
committerQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-08-29 17:00:18 +0800
commita716a04c831e4fb23cdd558756d8f393e4ef8d73 (patch)
treeb770c518314b8495f7e220ece9da4a10c6639546 /todolist/app.go
parent34639c4285621177efb10b82ddb07cd0017af56a (diff)
Refactor previous commits
Rewrite the `ManipulateNotes` function into `HandleNotes`, which routes the note sub-commands to calls of newly-written `Parse*Note` functions. On successful parse, these functions return true, and false otherwise. Related tests are also refined.
Diffstat (limited to 'todolist/app.go')
-rw-r--r--todolist/app.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/todolist/app.go b/todolist/app.go
index 79e3aad..92ee64d 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -137,23 +137,33 @@ func (a *App) ExpandTodo(input string) {
fmt.Println("Todo expanded.")
}
-func (a *App) ManipulateNotes(input string) {
+func (a *App) HandleNotes(input string) {
a.Load()
id := a.getId(input)
- parser := &Parser{}
+ if id == -1 {
+ return
+ }
todo := a.TodoList.FindById(id)
if todo == nil {
fmt.Println("No such id.")
return
}
+ parser := &Parser{}
- retStr := parser.ParseNotes(todo, input)
- if retStr != "" {
- a.Save()
- if retStr != "list" {
- fmt.Println("Notes " + retStr + "ed.")
- }
+ if parser.ParseAddNote(todo, input) {
+ fmt.Println("Note added.")
+ } else if parser.ParseDeleteNote(todo, input) {
+ fmt.Println("Note deleted.")
+ } else if parser.ParseEditNote(todo, input) {
+ fmt.Println("Note edited.")
+ } else if parser.ParseShowNote(todo, input) {
+ groups := map[string][]*Todo{}
+ groups[""] = append(groups[""], todo)
+ formatter := NewFormatter(&GroupedTodos{Groups: groups})
+ formatter.Print(true)
+ return
}
+ a.Save()
}
func (a *App) ArchiveCompleted() {