diff options
| -rw-r--r-- | todolist/app.go | 4 | ||||
| -rw-r--r-- | todolist/parser.go | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/todolist/app.go b/todolist/app.go index 44d97f5..45b9812 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -25,6 +25,10 @@ func (a *App) AddTodo(input string) { a.Load() parser := &Parser{} todo := parser.ParseNewTodo(input) + if todo == nil { + fmt.Println("I need more information. Try something like 'todo a chat with @bob due tom'") + return + } a.TodoList.Add(todo) a.Save() diff --git a/todolist/parser.go b/todolist/parser.go index c52f131..767785b 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -13,6 +13,12 @@ import ( type Parser struct{} func (p *Parser) ParseNewTodo(input string) *Todo { + r, _ := regexp.Compile(`^(add|a)(\\ |)`) + input = r.ReplaceAllString(input, "") + if input == "" { + return nil + } + todo := NewTodo() todo.Subject = p.Subject(input) todo.Projects = p.Projects(input) @@ -24,8 +30,6 @@ func (p *Parser) ParseNewTodo(input string) *Todo { } func (p *Parser) Subject(input string) string { - r, _ := regexp.Compile(`^(add|a) `) - input = r.ReplaceAllString(input, "") if strings.Contains(input, " due") { index := strings.LastIndex(input, " due") return input[0:index] |
