From f00bb3e8ed6ea5876c54e33a28c08a19a639c6bb Mon Sep 17 00:00:00 2001 From: Bunchhieng Date: Sun, 11 Sep 2016 15:10:12 -0400 Subject: Only open browser if .todos.json exists --- .todos.json | 1 - todo.go | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.todos.json b/.todos.json index ab83a99..e69de29 100644 --- a/.todos.json +++ b/.todos.json @@ -1 +0,0 @@ -[{"id":1,"subject":"support for priorities +feature","projects":["feature"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":2,"subject":"fix bug with 'tod' not being recognized +bug","projects":["bug"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":3,"subject":"separate into packages/directories +refactor","projects":["refactor"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":4,"subject":"+documentation re-record how it works using this https://asciinema.org/","projects":["documentation"],"contexts":[],"due":"","completed":false,"archived":false},{"id":5,"subject":"+slideplayer nice quote support","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":6,"subject":"+slideplayer image filters using css3","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":7,"subject":"+slideplayer syntax highlighting and code blocks","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":8,"subject":"+slideplayer presenter notes","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false}] \ No newline at end of file diff --git a/todo.go b/todo.go index 74782ef..6560fb0 100644 --- a/todo.go +++ b/todo.go @@ -128,9 +128,21 @@ func routeInput(command string, input string) { case "init": app.InitializeRepo() case "web": - 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() + // Only open default browser if .todos.json exists + pwd, err := os.Getwd() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + if _, err := os.Stat(pwd + "/.todos.json"); err == nil { + 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) + } } } -- cgit v1.3 From e7eb2b8f8cee7ebdf170173617a699e2e023db9b Mon Sep 17 00:00:00 2001 From: Bunchhieng Date: Sun, 11 Sep 2016 15:11:08 -0400 Subject: Only open browser if .todos.json exists --- .todos.json | 1 + todo.go | 1 + 2 files changed, 2 insertions(+) diff --git a/.todos.json b/.todos.json index e69de29..726fc95 100644 --- a/.todos.json +++ b/.todos.json @@ -0,0 +1 @@ +[{"id":1,"subject":"support for priorities +feature","projects":["feature"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":2,"subject":"fix bug with 'tod' not being recognized +bug","projects":["bug"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":3,"subject":"separate into packages/directories +refactor","projects":["refactor"],"contexts":[],"due":"2016-07-08","completed":false,"archived":false},{"id":4,"subject":"+documentation re-record how it works using this https://asciinema.org/","projects":["documentation"],"contexts":[],"due":"","completed":false,"archived":false},{"id":5,"subject":"+slideplayer nice quote support","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":6,"subject":"+slideplayer image filters using css3","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":7,"subject":"+slideplayer syntax highlighting and code blocks","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false},{"id":8,"subject":"+slideplayer presenter notes","projects":["slideplayer"],"contexts":[],"due":"","completed":false,"archived":false}] diff --git a/todo.go b/todo.go index 6560fb0..8a95142 100644 --- a/todo.go +++ b/todo.go @@ -134,6 +134,7 @@ func routeInput(command string, input string) { fmt.Println(err) os.Exit(1) } + if _, err := os.Stat(pwd + "/.todos.json"); err == nil { web := todolist.NewWebapp() fmt.Println("Now serving todolist web.\nHead to http://localhost:7890 to see your todo list!") -- cgit v1.3 From 695c8ad53213041d9904ef2c8648ecc10df69f5e Mon Sep 17 00:00:00 2001 From: Bunchhieng Date: Sun, 11 Sep 2016 15:11:48 -0400 Subject: Only open browser if .todos.json exists --- todo.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/todo.go b/todo.go index 8a95142..b71d215 100644 --- a/todo.go +++ b/todo.go @@ -130,11 +130,11 @@ func routeInput(command string, input string) { case "web": // Only open default browser if .todos.json exists pwd, err := os.Getwd() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - + if err != nil { + fmt.Println(err) + os.Exit(1) + } + if _, err := os.Stat(pwd + "/.todos.json"); err == nil { web := todolist.NewWebapp() fmt.Println("Now serving todolist web.\nHead to http://localhost:7890 to see your todo list!") -- cgit v1.3