diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-05-25 09:56:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-25 09:56:02 -0400 |
| commit | e015094d20811d30676014d60d8219fa0fa63e8a (patch) | |
| tree | 5ba56e64e881cd0e0cdff4037033e5003d570c8c /todolist/parser.go | |
| parent | 6cb4a95af8bc4a8348c7b115fba334e668fe95e5 (diff) | |
| parent | f70fd56e6f2144f19150fb0fca2508a5897ab48b (diff) | |
Merge pull request #62 from gammons/unified-edit
Unified edit
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) } } |
