From 0d1eecc168321dbfd56d1fec55c7d6df5eee2c29 Mon Sep 17 00:00:00 2001 From: Quey-Liang Kao Date: Sat, 21 Jan 2017 04:33:46 +0800 Subject: New Feature: Expanding existing todos --- todolist/app.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'todolist/app.go') diff --git a/todolist/app.go b/todolist/app.go index 58b4801..e67605f 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -4,6 +4,7 @@ import ( "fmt" "regexp" "strconv" + "strings" "time" ) @@ -102,6 +103,33 @@ func (a *App) EditTodoDue(input string) { fmt.Println("Todo due date updated.") } +func (a *App) ExpandTodo(input string) { + a.Load() + id, _ := a.getId(input) + parser := &Parser{} + if id == -1 { + return + } + + commonProject := parser.ExpandProject(input) + todos := strings.LastIndex(input, ":") + if commonProject == "" || len(input) <= todos+1 || todos == -1 { + fmt.Println("I'm expecting a format like \"todolist ex : , , ...\"") + return + } + + newTodos := strings.Split(input[todos+1:], ",") + + for _, todo := range newTodos { + args := []string{"add +", commonProject, " ", todo} + a.AddTodo(strings.Join(args, "")) + } + + a.TodoList.Delete(id) + a.Save() + fmt.Println("Todo expanded.") +} + func (a *App) ArchiveCompleted() { a.Load() for _, todo := range a.TodoList.Todos() { -- cgit v1.3