diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-01-26 05:45:49 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-26 05:45:49 -0600 |
| commit | bfd33a9904daac273ff2b708d02c738be276b8c7 (patch) | |
| tree | e2ff4b783ce6e856c89b779e72bc4a3eb40b9eaf /todolist/app.go | |
| parent | 4c53c6f4755f3b50287efced0b0db7e1c6b4fa54 (diff) | |
| parent | 206a28076422758102fb7df322b218dfe4248deb (diff) | |
Merge pull request #27 from gammons/issue/proposal-expand
New Feature: Expanding existing todos
Diffstat (limited to 'todolist/app.go')
| -rw-r--r-- | todolist/app.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/todolist/app.go b/todolist/app.go index 58b4801..5f26d45 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 <project>: <todo1>, <todo2>, ...\"") + 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() { |
