aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/app.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-05-05 16:51:03 -0400
committerGrant Ammons <gammons@gmail.com>2017-05-09 20:20:24 -0400
commit1056fecdccbb734dc732a2f795f2591d3c63f951 (patch)
treeb2ee655bd093e27377dbbbee6005f46d429abd6c /todolist/app.go
parent54aaabdbe16986e6e6071dda1eeee6f73ae39400 (diff)
WIP on a unified edit
This allows a unified edit functionality that supports the following: **`t e 25 due tom`** * Edits the due date * Leaves subject, projects and contexts unchanged **`t e 25 take out the trash with @bob` * Updates the subject, projects and contexts * Leaves the due date unchanged **`t e 25 take out the trash with @bob due tom` * Updates the subject, projects and contexts * Updates the due date **What's missing** * Tests that exercise this functionality
Diffstat (limited to 'todolist/app.go')
-rw-r--r--todolist/app.go53
1 files changed, 21 insertions, 32 deletions
diff --git a/todolist/app.go b/todolist/app.go
index 12cc39d..9fefd8e 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -3,8 +3,8 @@ package todolist
import (
"fmt"
"regexp"
+ "strconv"
"strings"
- "time"
)
type App struct {
@@ -91,38 +91,18 @@ func (a *App) UnarchiveTodo(input string) {
fmt.Println("Todo unarchived.")
}
-func (a *App) EditTodoSubject(input string) {
+func (a *App) EditTodo(input string) {
a.Load()
-
- p := Parser{input}
- _, id, subject := p.Parse()
+ id, _ := a.getId(input)
if id == -1 {
return
}
+ parser := &Parser{}
- _, todo := a.getId(input)
- if todo == nil {
- return
- }
-
- todo.Subject = subject
- todo.Projects = p.Projects(subject)
- todo.Contexts = p.Contexts(subject)
-
- a.Save()
- fmt.Println("Todo subject updated.")
-}
-
-func (a *App) EditTodoDue(input string) {
- a.Load()
- id, todo := a.getId(input)
- if id == -1 {
- return
+ if (parser.ParseEditTodo(a.TodoList.FindById(id), input)) {
+ a.Save()
+ fmt.Println("Todo updated.")
}
- parser := &Parser{}
- todo.Due = parser.Due(input, time.Now())
- a.Save()
- fmt.Println("Todo due date updated.")
}
func (a *App) ExpandTodo(input string) {
@@ -195,13 +175,22 @@ func (a *App) UnprioritizeTodo(input string) {
}
func (a *App) getId(input string) (int, *Todo) {
- _, id, _ := Parser{input}.Parse()
- todo := a.TodoList.FindById(id)
- if todo == nil {
- fmt.Println("No such id.")
+ re, _ := regexp.Compile("\\d+")
+ if re.MatchString(input) {
+ id, _ := strconv.Atoi(re.FindString(input))
+ todo := a.TodoList.FindById(id)
+ if todo == nil {
+ fmt.Println("No such id.")
+ return -1, nil
+
+ }
+ return id, todo
+
+ } else {
+ fmt.Println("Invalid id.")
return -1, nil
+
}
- return id, todo
}
func (a *App) getGroups(input string, todos []*Todo) *GroupedTodos {