diff options
| author | Bunchhieng <Bunchhieng@gmail.com> | 2016-09-11 15:10:12 -0400 |
|---|---|---|
| committer | Bunchhieng <Bunchhieng@gmail.com> | 2016-09-11 15:10:12 -0400 |
| commit | f00bb3e8ed6ea5876c54e33a28c08a19a639c6bb (patch) | |
| tree | 046697f965d95e82e5dd27774ec4fbcd4f1f9b31 /todo.go | |
| parent | 832a27475b773e7a63cc0b582be8d7871de75dc3 (diff) | |
Only open browser if .todos.json exists
Diffstat (limited to 'todo.go')
| -rw-r--r-- | todo.go | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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) + } } } |
