From aa5050461a30d36a384edd45d20585a89d3da344 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Sat, 29 Apr 2017 16:19:24 +0200 Subject: extract subcommand, id, and input string in Parser --- todolist/app.go | 17 +++++------------ todolist/parser.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 880390e..24ebe4d 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -3,7 +3,6 @@ package todolist import ( "fmt" "regexp" - "strconv" "strings" "time" ) @@ -174,19 +173,13 @@ func (a *App) UnprioritizeTodo(input string) { } func (a *App) getId(input string) (int, *Todo) { - 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.") + _, id, _ := Parser{input}.Parse() + todo := a.TodoList.FindById(id) + if todo == nil { + fmt.Println("No such id.") return -1, nil } + return id, todo } func (a *App) getGroups(input string, todos []*Todo) *GroupedTodos { diff --git a/todolist/parser.go b/todolist/parser.go index 1f070c3..d55ab3b 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -9,7 +9,9 @@ import ( "time" ) -type Parser struct{} +type Parser struct { + input string +} func (p *Parser) ParseNewTodo(input string) *Todo { r, _ := regexp.Compile(`^(add|a)(\\ |) `) @@ -28,6 +30,19 @@ func (p *Parser) ParseNewTodo(input string) *Todo { return todo } +func (p Parser) Parse() (string, int, string) { + input := p.input + r := regexp.MustCompile(`(\w+) (\d+) (.*)`) + matches := r.FindStringSubmatch(input) + id, err := strconv.Atoi(matches[2]) + if err != nil { + fmt.Println("Invalid id.") + id = -1 + } + + return matches[1], id, matches[3] +} + func (p *Parser) Subject(input string) string { if strings.Contains(input, " due") { index := strings.LastIndex(input, " due") -- cgit v1.3 From ed6ab22cbdbc475adf539637e45a67811ec0c15a Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Sat, 29 Apr 2017 16:31:31 +0200 Subject: display an error on malformed input --- todolist/app.go | 12 ++++++++++++ todolist/parser.go | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'todolist') 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] -- cgit v1.3 From d2df88f217cef638bdca527794969fcaa835bfd7 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Tue, 2 May 2017 17:00:26 +0200 Subject: add test for func (p Parser) Parse() --- todolist/parser_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'todolist') diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 8cd6b53..9dfa454 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -169,3 +169,24 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", septemberTime)) assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } + +func TestParseCommandIdSubject(t *testing.T) { + assert := assert.New(t) + parser := Parser{"es 24 a new subject"} + command, id, subject := parser.Parse() + + assert.Equal("es", command) + assert.Equal(24, id) + assert.Equal("a new subject", subject) +} + +func TestParseInvalidCommandIdSubject(t *testing.T) { + assert := assert.New(t) + input := "es a new project" + parser := Parser{input} + command, id, subject := parser.Parse() + + assert.Equal("", command) + assert.Equal(-1, id) + assert.Equal(input, subject) +} -- cgit v1.3 From bb2c579f02e9d273058a6d4d55593622923aaf9f Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 10:42:15 +0200 Subject: allow any whitespace between subcommand, id and input --- todolist/parser.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index 38bdb7f..616e82f 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -30,18 +30,20 @@ func (p *Parser) ParseNewTodo(input string) *Todo { return todo } -func (p Parser) Parse() (string, int, string) { - input := p.input - r := regexp.MustCompile(`(\w+) (\d+) (.*)`) - matches := r.FindStringSubmatch(input) +// Parse accepts user input and splits it into subcommand, the todo id to +// work on and the input to the subcommand function. +func (p Parser) Parse() (subcommand string, id int, input string) { + r := regexp.MustCompile(`(\w+)\s+(\d+)\s+(.*)`) + matches := r.FindStringSubmatch(p.input) if len(matches) < 4 { fmt.Println("Could match command, id or subject") - return "", -1, input + return "", -1, "" } + + // because of the regexp match, this can never fail id, err := strconv.Atoi(matches[2]) if err != nil { - fmt.Println("Invalid id.") - return "", -1, input + panic(err) } return matches[1], id, matches[3] -- cgit v1.3 From 950aabce192d6dd15eee60717a510be2bb4f9c7c Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 10:59:26 +0200 Subject: test multiple whitespace --- todolist/parser_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 9dfa454..05f390a 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -170,6 +170,16 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } +func TestParseCommandIdSubjectWhitespace(t *testing.T) { + assert := assert.New(t) + parser := Parser{"es 24\t a new subject"} + command, id, subject := parser.Parse() + + assert.Equal("es", command) + assert.Equal(24, id) + assert.Equal("a new subject", subject) +} + func TestParseCommandIdSubject(t *testing.T) { assert := assert.New(t) parser := Parser{"es 24 a new subject"} @@ -188,5 +198,5 @@ func TestParseInvalidCommandIdSubject(t *testing.T) { assert.Equal("", command) assert.Equal(-1, id) - assert.Equal(input, subject) + assert.Equal("", subject) } -- cgit v1.3 From 2c5512341a8c87dfe4d37106a1ecc02784e84da6 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 14:54:32 +0200 Subject: prevent duplicate error messages when updating subjects --- todolist/app.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 6d771ef..1e9f699 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -93,12 +93,15 @@ func (a *App) UnarchiveTodo(input string) { func (a *App) EditTodoSubject(input string) { a.Load() + _, id, subject := Parser{input}.Parse() - id, todo := a.getId(input) if id == -1 { return } + + _, todo := a.getId(input) todo.Subject = subject + a.Save() fmt.Println("Todo subject updated.") } -- cgit v1.3 From fdca747e173c20f59901207c3f1887cece2a9351 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 15:18:13 +0200 Subject: subcommands like delete don't take a subject, so make it optional --- todolist/parser.go | 18 ++++++++++++------ todolist/parser_test.go | 10 ++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index 616e82f..3598e12 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -31,22 +31,28 @@ func (p *Parser) ParseNewTodo(input string) *Todo { } // Parse accepts user input and splits it into subcommand, the todo id to -// work on and the input to the subcommand function. -func (p Parser) Parse() (subcommand string, id int, input string) { - r := regexp.MustCompile(`(\w+)\s+(\d+)\s+(.*)`) +// work on and the subject for the subcommand function. +func (p Parser) Parse() (subcommand string, id int, subject string) { + r := regexp.MustCompile(`(\w+)\s+(\d+)(\s+(.*))?`) matches := r.FindStringSubmatch(p.input) - if len(matches) < 4 { - fmt.Println("Could match command, id or subject") + if len(matches) < 3 { + fmt.Println("Could match command or id") return "", -1, "" } + subcommand = matches[1] + // because of the regexp match, this can never fail id, err := strconv.Atoi(matches[2]) if err != nil { panic(err) } - return matches[1], id, matches[3] + if len(matches) == 5 { + subject = matches[4] + } + + return } func (p *Parser) Subject(input string) string { diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 05f390a..4466489 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -170,6 +170,16 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } +func TestParseCommandIdSubjectOptionalSubject(t *testing.T) { + assert := assert.New(t) + parser := Parser{"d 24"} + command, id, subject := parser.Parse() + + assert.Equal("d", command) + assert.Equal(24, id) + assert.Equal("", subject) +} + func TestParseCommandIdSubjectWhitespace(t *testing.T) { assert := assert.New(t) parser := Parser{"es 24\t a new subject"} -- cgit v1.3 From 6beb1258b010cbb29f8c296a3a1d51cae2f18aa4 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 18:13:00 +0200 Subject: error out when invalid id given --- todolist/app.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 1e9f699..77a7e44 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -100,6 +100,10 @@ func (a *App) EditTodoSubject(input string) { } _, todo := a.getId(input) + if todo == nil { + fmt.Println("Todo not found.") + return + } todo.Subject = subject a.Save() -- cgit v1.3 From 87e2fe7dbfcb2026662b50524d5d9eec766d8308 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Wed, 3 May 2017 18:33:01 +0200 Subject: do not duplicate error messages again --- todolist/app.go | 1 - 1 file changed, 1 deletion(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 77a7e44..5f4d08f 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -101,7 +101,6 @@ func (a *App) EditTodoSubject(input string) { _, todo := a.getId(input) if todo == nil { - fmt.Println("Todo not found.") return } todo.Subject = subject -- cgit v1.3 From 54aaabdbe16986e6e6071dda1eeee6f73ae39400 Mon Sep 17 00:00:00 2001 From: Michael Strüder Date: Thu, 4 May 2017 23:55:43 +0200 Subject: parse Projects and Contexts when editing subject --- todolist/app.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 5f4d08f..12cc39d 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -94,7 +94,8 @@ func (a *App) UnarchiveTodo(input string) { func (a *App) EditTodoSubject(input string) { a.Load() - _, id, subject := Parser{input}.Parse() + p := Parser{input} + _, id, subject := p.Parse() if id == -1 { return } @@ -103,7 +104,10 @@ func (a *App) EditTodoSubject(input string) { if todo == nil { return } + todo.Subject = subject + todo.Projects = p.Projects(subject) + todo.Contexts = p.Contexts(subject) a.Save() fmt.Println("Todo subject updated.") -- cgit v1.3 From 1056fecdccbb734dc732a2f795f2591d3c63f951 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Fri, 5 May 2017 16:51:03 -0400 Subject: 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 --- todo.go | 6 ++---- todolist/app.go | 53 +++++++++++++++++++++-------------------------------- todolist/parser.go | 30 ++++++++++++------------------ 3 files changed, 35 insertions(+), 54 deletions(-) (limited to 'todolist') diff --git a/todo.go b/todo.go index d091cd3..130fd55 100644 --- a/todo.go +++ b/todo.go @@ -140,10 +140,8 @@ func routeInput(command string, input string) { app.UnarchiveTodo(input) case "ac": app.ArchiveCompleted() - case "e", "edit", "ed", "edit-date": - app.EditTodoDue(input) - case "es", "edit-subject": - app.EditTodoSubject(input) + case "e", "edit": + app.EditTodo(input) case "ex", "expand": app.ExpandTodo(input) case "gc": 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 { 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 { -- cgit v1.3 From 423d2a238487c21ef36621bf93442c87504bfc7c Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 9 May 2017 19:58:26 -0400 Subject: Trim space of the subject --- todolist/parser.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index 91f9b6e..4a0e5be 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -52,9 +52,9 @@ func (p *Parser) ParseEditTodo(todo *Todo, input string) bool { 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) } } -- cgit v1.3 From 580183ad7f155e4cdce047bdeb22fd775be69fc8 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 9 May 2017 20:17:33 -0400 Subject: Update the tests * Test editing a todo with just a due date does not affect subject * Test editing a todo with just subject does not affect due date * Editing a subject should also update projects and contexts --- todolist/parser_test.go | 79 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 25 deletions(-) (limited to 'todolist') diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 4466489..6920c7c 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -170,43 +170,72 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } -func TestParseCommandIdSubjectOptionalSubject(t *testing.T) { +func TestParseEditTodoJustDate(t *testing.T) { assert := assert.New(t) - parser := Parser{"d 24"} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := NewTodo() + tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 due tom") + + assert.Equal(todo.Due, tomorrow) +} + +func TestParseEditTodoJustDateDoesNotEditExistingSubject(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := NewTodo() + todo.Subject = "pick up the trash" + tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 due tom") - assert.Equal("d", command) - assert.Equal(24, id) - assert.Equal("", subject) + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "pick up the trash") } -func TestParseCommandIdSubjectWhitespace(t *testing.T) { +func TestParseEditTodoJustSubject(t *testing.T) { assert := assert.New(t) - parser := Parser{"es 24\t a new subject"} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := &Todo{Subject: "pick up the trash", Due: "2016-11-25"} + + parser.ParseEditTodo(todo, "e 24 changed the todo") - assert.Equal("es", command) - assert.Equal(24, id) - assert.Equal("a new subject", subject) + assert.Equal(todo.Due, "2016-11-25") + assert.Equal(todo.Subject, "changed the todo") } -func TestParseCommandIdSubject(t *testing.T) { +func TestParseEditTodoSubjectUpdatesProjectsAndContexts(t *testing.T) { assert := assert.New(t) - parser := Parser{"es 24 a new subject"} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := &Todo{ + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", + Projects: []string{"trash"}, + Contexts: []string{"dad"}, + } - assert.Equal("es", command) - assert.Equal(24, id) - assert.Equal("a new subject", subject) + parser.ParseEditTodo(todo, "e 24 get the +garbage with @mom") + + assert.Equal(todo.Due, "2016-11-25") + assert.Equal(todo.Subject, "get the +garbage with @mom") + assert.Equal(todo.Projects, []string{"garbage"}) + assert.Equal(todo.Contexts, []string{"mom"}) } -func TestParseInvalidCommandIdSubject(t *testing.T) { +func TestParseEditTodoWithSubjectAndDue(t *testing.T) { assert := assert.New(t) - input := "es a new project" - parser := Parser{input} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := &Todo{ + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", + Projects: []string{"trash"}, + Contexts: []string{"dad"}, + } + tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 get the +garbage with @mom due tom") - assert.Equal("", command) - assert.Equal(-1, id) - assert.Equal("", subject) + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "get the +garbage with @mom") } -- cgit v1.3 From 55af0a2d91c8e72ebe54b00f8b023d4e46686287 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 9 May 2017 20:34:56 -0400 Subject: Minor optimization --- todolist/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index 9fefd8e..eb2f5c2 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -93,13 +93,13 @@ func (a *App) UnarchiveTodo(input string) { func (a *App) EditTodo(input string) { a.Load() - id, _ := a.getId(input) + id, todo := a.getId(input) if id == -1 { return } parser := &Parser{} - if (parser.ParseEditTodo(a.TodoList.FindById(id), input)) { + if (parser.ParseEditTodo(todo, input)) { a.Save() fmt.Println("Todo updated.") } -- cgit v1.3 From 14502a4dee75e0da0915061f15928efb44d2b1ab Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Wed, 10 May 2017 20:21:15 -0400 Subject: Formatting --- todolist/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index 4a0e5be..0d48c92 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -9,7 +9,7 @@ import ( "time" ) -type Parser struct {} +type Parser struct{} func (p *Parser) ParseNewTodo(input string) *Todo { r, _ := regexp.Compile(`^(add|a)(\\ |) `) -- cgit v1.3 From d86bc4ea3f85bab91be80792c423b2a96aa6d626 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Wed, 10 May 2017 20:21:41 -0400 Subject: Formatting for test --- todolist/parser_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'todolist') diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 6920c7c..f5cc185 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -174,7 +174,7 @@ func TestParseEditTodoJustDate(t *testing.T) { assert := assert.New(t) parser := &Parser{} todo := NewTodo() - tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") parser.ParseEditTodo(todo, "e 24 due tom") @@ -186,7 +186,7 @@ func TestParseEditTodoJustDateDoesNotEditExistingSubject(t *testing.T) { parser := &Parser{} todo := NewTodo() todo.Subject = "pick up the trash" - tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") parser.ParseEditTodo(todo, "e 24 due tom") @@ -209,8 +209,8 @@ func TestParseEditTodoSubjectUpdatesProjectsAndContexts(t *testing.T) { assert := assert.New(t) parser := &Parser{} todo := &Todo{ - Subject: "pick up the +trash with @dad", - Due: "2016-11-25", + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", Projects: []string{"trash"}, Contexts: []string{"dad"}, } @@ -227,12 +227,12 @@ func TestParseEditTodoWithSubjectAndDue(t *testing.T) { assert := assert.New(t) parser := &Parser{} todo := &Todo{ - Subject: "pick up the +trash with @dad", - Due: "2016-11-25", + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", Projects: []string{"trash"}, Contexts: []string{"dad"}, } - tomorrow := time.Now().AddDate(0,0,1).Format("2006-01-02") + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") parser.ParseEditTodo(todo, "e 24 get the +garbage with @mom due tom") -- cgit v1.3 From aed8e547d1b91c607853737960bbf9df4ab6756b Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Wed, 10 May 2017 20:38:55 -0400 Subject: Remove unnecessary parens --- todolist/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/app.go b/todolist/app.go index eb2f5c2..56787d3 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -99,7 +99,7 @@ func (a *App) EditTodo(input string) { } parser := &Parser{} - if (parser.ParseEditTodo(todo, input)) { + if parser.ParseEditTodo(todo, input) { a.Save() fmt.Println("Todo updated.") } -- cgit v1.3 From f70fd56e6f2144f19150fb0fca2508a5897ab48b Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Wed, 10 May 2017 20:39:55 -0400 Subject: fix typo --- todolist/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index 0d48c92..256e782 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -32,7 +32,7 @@ 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 match command or id") + fmt.Println("Could not match command or id") return false } -- cgit v1.3