aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-05-04 14:09:02 -0400
committerGrant Ammons <gammons@gmail.com>2016-05-04 14:09:02 -0400
commit86be4b4dec5c920f227ef487a19b3472981ffcac (patch)
treeb2d889e8b38df43b5d77ffdeb182a93d3b37f195
parente66354be816cef8b64cf3c629790c1e9f90d64fd (diff)
Add edit command for due dates
-rw-r--r--todo.go24
-rw-r--r--todolist/app.go14
2 files changed, 29 insertions, 9 deletions
diff --git a/todo.go b/todo.go
index 3b74943..6cbc6ea 100644
--- a/todo.go
+++ b/todo.go
@@ -90,6 +90,10 @@ func usage() {
yellow.Println("\ttodo l archived")
fmt.Println("\tlist all archived todos\n")
+ blueBold.Println("\nEditing due dates")
+ yellow.Println("\ttodo e 33 due mon")
+ fmt.Println("\tEdits the todo with 33 and sets the due date to this coming Monday\n")
+
blueBold.Println("\nDeleting")
yellow.Println("\ttodo d 33")
fmt.Println("\tDeletes a todo with id 33\n")
@@ -97,22 +101,24 @@ func usage() {
func routeInput(command string, input string) {
app := todolist.NewApp()
- switch {
- case command == "l" || command == "list":
+ switch command {
+ case "l", "list":
app.ListTodos(input)
- case command == "a" || command == "add":
+ case "a", "add":
app.AddTodo(input)
- case command == "d" || command == "del":
+ case "d", "del":
app.DeleteTodo(input)
- case command == "c" || command == "complete":
+ case "c", "complete":
app.CompleteTodo(input)
- case command == "uc" || command == "uncomplete":
+ case "uc", "uncomplete":
app.UncompleteTodo(input)
- case command == "ar" || command == "archive":
+ case "ar", "archive":
app.ArchiveTodo(input)
- case command == "uar" || command == "unarchive":
+ case "uar", "unarchive":
app.UnarchiveTodo(input)
- case command == "ac":
+ case "ac":
app.ArchiveCompleted()
+ case "e", "edit":
+ app.EditTodoDue(input)
}
}
diff --git a/todolist/app.go b/todolist/app.go
index be40eb3..0d3ce95 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"strconv"
+ "time"
)
type App struct {
@@ -80,6 +81,19 @@ func (a *App) UnarchiveTodo(input string) {
}
}
+func (a *App) EditTodoDue(input string) {
+ id := a.getId(input)
+ if id != -1 {
+ todo := a.TodoStore.FindById(id)
+ parser := &Parser{}
+ todo.Due = parser.Due(input, time.Now())
+ a.TodoStore.Save()
+ fmt.Println("Todo due date updated.")
+ } else {
+ fmt.Println("Could not find id.")
+ }
+}
+
func (a *App) ArchiveCompleted() {
for _, todo := range a.TodoStore.Todos() {
if todo.Completed {