diff options
| author | Michael Strùˆder <mikezter@gmail.com> | 2017-04-29 16:19:24 +0200 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2017-05-09 20:20:24 -0400 |
| commit | aa5050461a30d36a384edd45d20585a89d3da344 (patch) | |
| tree | 4785f5faa2dc1c2780fe3f778e3fdc58a0045215 /todolist/app.go | |
| parent | 6cb4a95af8bc4a8348c7b115fba334e668fe95e5 (diff) | |
extract subcommand, id, and input string in Parser
Diffstat (limited to 'todolist/app.go')
| -rw-r--r-- | todolist/app.go | 17 |
1 files changed, 5 insertions, 12 deletions
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 { |
