diff options
| -rw-r--r-- | todolist/app.go | 12 | ||||
| -rw-r--r-- | todolist/parser.go | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/todolist/app.go b/todolist/app.go index 24ebe4d..6d771ef 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -91,6 +91,18 @@ func (a *App) UnarchiveTodo(input string) { fmt.Println("Todo unarchived.") } +func (a *App) EditTodoSubject(input string) { + a.Load() + _, id, subject := Parser{input}.Parse() + id, todo := a.getId(input) + if id == -1 { + return + } + todo.Subject = subject + a.Save() + fmt.Println("Todo subject updated.") +} + func (a *App) EditTodoDue(input string) { a.Load() id, todo := a.getId(input) diff --git a/todolist/parser.go b/todolist/parser.go index d55ab3b..38bdb7f 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -34,10 +34,14 @@ func (p Parser) Parse() (string, int, string) { input := p.input r := regexp.MustCompile(`(\w+) (\d+) (.*)`) matches := r.FindStringSubmatch(input) + if len(matches) < 4 { + fmt.Println("Could match command, id or subject") + return "", -1, input + } id, err := strconv.Atoi(matches[2]) if err != nil { fmt.Println("Invalid id.") - id = -1 + return "", -1, input } return matches[1], id, matches[3] |
