diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-05-05 16:51:03 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2017-05-09 20:20:24 -0400 |
| commit | 1056fecdccbb734dc732a2f795f2591d3c63f951 (patch) | |
| tree | b2ee655bd093e27377dbbbee6005f46d429abd6c /todolist/parser.go | |
| parent | 54aaabdbe16986e6e6071dda1eeee6f73ae39400 (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/parser.go')
| -rw-r--r-- | todolist/parser.go | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/todolist/parser.go b/todolist/parser.go index 3598e12..91f9b6e 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -9,9 +9,7 @@ import ( "time" ) -type Parser struct { - input string -} +type Parser struct {} func (p *Parser) ParseNewTodo(input string) *Todo { r, _ := regexp.Compile(`^(add|a)(\\ |) `) @@ -30,29 +28,25 @@ func (p *Parser) ParseNewTodo(input string) *Todo { return todo } -// Parse accepts user input and splits it into subcommand, the todo id to -// work on and the subject for the subcommand function. -func (p Parser) Parse() (subcommand string, id int, subject string) { +func (p *Parser) ParseEditTodo(todo *Todo, input string) bool { r := regexp.MustCompile(`(\w+)\s+(\d+)(\s+(.*))?`) - matches := r.FindStringSubmatch(p.input) + matches := r.FindStringSubmatch(input) if len(matches) < 3 { fmt.Println("Could match command or id") - return "", -1, "" + return false } - subcommand = matches[1] + subjectOnly := matches[3] - // because of the regexp match, this can never fail - id, err := strconv.Atoi(matches[2]) - if err != nil { - panic(err) + if p.Subject(subjectOnly) != "" { + todo.Subject = p.Subject(subjectOnly) + todo.Projects = p.Projects(subjectOnly) + todo.Contexts = p.Contexts(subjectOnly) } - - if len(matches) == 5 { - subject = matches[4] + if p.hasDue(subjectOnly) { + todo.Due = p.Due(subjectOnly, time.Now()) } - - return + return true } func (p *Parser) Subject(input string) string { |
