diff options
Diffstat (limited to 'todolist/parser.go')
| -rw-r--r-- | todolist/parser.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/todolist/parser.go b/todolist/parser.go index 1f070c3..256e782 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -28,12 +28,33 @@ func (p *Parser) ParseNewTodo(input string) *Todo { return todo } +func (p *Parser) ParseEditTodo(todo *Todo, input string) bool { + r := regexp.MustCompile(`(\w+)\s+(\d+)(\s+(.*))?`) + matches := r.FindStringSubmatch(input) + if len(matches) < 3 { + fmt.Println("Could not match command or id") + return false + } + + subjectOnly := matches[3] + + if p.Subject(subjectOnly) != "" { + todo.Subject = p.Subject(subjectOnly) + todo.Projects = p.Projects(subjectOnly) + todo.Contexts = p.Contexts(subjectOnly) + } + if p.hasDue(subjectOnly) { + todo.Due = p.Due(subjectOnly, time.Now()) + } + return true +} + func (p *Parser) Subject(input string) string { if strings.Contains(input, " due") { index := strings.LastIndex(input, " due") - return input[0:index] + return strings.TrimSpace(input[0:index]) } else { - return input + return strings.TrimSpace(input) } } |
