aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--todo.go13
-rw-r--r--todolist/app.go9
-rw-r--r--todolist/file_store.go6
-rw-r--r--todolist/parser.go2
-rw-r--r--todolist/parser_test.go8
5 files changed, 22 insertions, 16 deletions
diff --git a/todo.go b/todo.go
index b71d215..2b95c98 100644
--- a/todo.go
+++ b/todo.go
@@ -128,22 +128,13 @@ func routeInput(command string, input string) {
case "init":
app.InitializeRepo()
case "web":
- // Only open default browser if .todos.json exists
- pwd, err := os.Getwd()
- if err != nil {
- fmt.Println(err)
+ if err := app.Load(); err != nil {
os.Exit(1)
- }
-
- if _, err := os.Stat(pwd + "/.todos.json"); err == nil {
+ } else {
web := todolist.NewWebapp()
fmt.Println("Now serving todolist web.\nHead to http://localhost:7890 to see your todo list!")
open.Start("http://localhost:7890")
web.Run()
- } else {
- fmt.Println("No todo file found!")
- fmt.Println("Initialize a new todo repo by running 'todo init'")
- os.Exit(1)
}
}
}
diff --git a/todolist/app.go b/todolist/app.go
index 7f64366..44d97f5 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -153,8 +153,13 @@ func (a *App) getGroups(input string, todos []*Todo) *GroupedTodos {
return grouped
}
-func (a *App) Load() {
- a.TodoList.Load(a.TodoStore.Load())
+func (a *App) Load() error {
+ todos, err := a.TodoStore.Load()
+ if err != nil {
+ return err
+ }
+ a.TodoList.Load(todos)
+ return nil
}
func (a *App) Save() {
diff --git a/todolist/file_store.go b/todolist/file_store.go
index 61e6e7c..5413295 100644
--- a/todolist/file_store.go
+++ b/todolist/file_store.go
@@ -16,11 +16,12 @@ func NewFileStore() *FileStore {
return &FileStore{FileLocation: ".todos.json", Loaded: false}
}
-func (f *FileStore) Load() []*Todo {
+func (f *FileStore) Load() ([]*Todo, error) {
data, err := ioutil.ReadFile(f.FileLocation)
if err != nil {
fmt.Println("No todo file found!")
fmt.Println("Initialize a new todo repo by running 'todo init'")
+ return nil, err
os.Exit(0)
}
@@ -28,11 +29,12 @@ func (f *FileStore) Load() []*Todo {
jerr := json.Unmarshal(data, &todos)
if jerr != nil {
fmt.Println("Error reading json data", jerr)
+ return nil, jerr
os.Exit(1)
}
f.Loaded = true
- return todos
+ return todos, nil
}
func (f *FileStore) Initialize() {
diff --git a/todolist/parser.go b/todolist/parser.go
index c0c9c3c..433cfc6 100644
--- a/todolist/parser.go
+++ b/todolist/parser.go
@@ -61,7 +61,7 @@ func (p *Parser) Due(input string, day time.Time) string {
switch res {
case "none":
return ""
- case "today":
+ case "today", "tod":
return now.BeginningOfDay().Format("2006-01-02")
case "tomorrow", "tom":
return now.BeginningOfDay().AddDate(0, 0, 1).Format("2006-01-02")
diff --git a/todolist/parser_test.go b/todolist/parser_test.go
index 44ce3f7..37a4910 100644
--- a/todolist/parser_test.go
+++ b/todolist/parser_test.go
@@ -59,6 +59,10 @@ func TestDueToday(t *testing.T) {
if todo.Due != now.BeginningOfDay().Format("2006-01-02") {
fmt.Println("Date is different", todo.Due, time.Now())
}
+ todo = parser.ParseNewTodo("do this thing with @bob and @mary due tod")
+ if todo.Due != now.BeginningOfDay().Format("2006-01-02") {
+ fmt.Println("Date is different", todo.Due, time.Now())
+ }
}
func TestDueTomorrow(t *testing.T) {
@@ -67,6 +71,10 @@ func TestDueTomorrow(t *testing.T) {
if todo.Due != now.BeginningOfDay().AddDate(0, 0, 1).Format("2006-01-02") {
fmt.Println("Date is different", todo.Due, time.Now())
}
+ todo = parser.ParseNewTodo("do this thing with @bob and @mary due tom")
+ if todo.Due != now.BeginningOfDay().AddDate(0, 0, 1).Format("2006-01-02") {
+ fmt.Println("Date is different", todo.Due, time.Now())
+ }
}
func TestDueSpecific(t *testing.T) {