diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index 6497a0e..a753490 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -156,7 +156,9 @@ func main() { case "webserver": fs := flag.NewFlagSet("", flag.ExitOnError) should_auto_open := fs.Bool("auto-open", false, "") - fs.Parse(args[1:]) + if err := fs.Parse(args[1:]); err != nil { + panic(err) + } start_webserver(*addr, *should_auto_open) case "fetch_inbox": fetch_inbox(*how_many) diff --git a/internal/webserver/server.go b/internal/webserver/server.go index ebe8699..e371f14 100644 --- a/internal/webserver/server.go +++ b/internal/webserver/server.go @@ -9,8 +9,8 @@ import ( "net/http" "os" "os/exec" - "runtime" "path" + "runtime" "strconv" "strings" "time" @@ -156,14 +156,18 @@ func (app *Application) Run(address string, should_auto_open bool) { app.ErrorLog.Fatal(err) } -func openWebPage(url string) error { +func openWebPage(url string) { + var cmd *exec.Cmd switch runtime.GOOS { case "darwin": // macOS - return exec.Command("open", url).Run() + cmd = exec.Command("open", url) case "windows": - return exec.Command("cmd", "/c", "start", url).Run() + cmd = exec.Command("cmd", "/c", "start", url) default: // Linux and others - return exec.Command("xdg-open", url).Run() + cmd = exec.Command("xdg-open", url) + } + if err := cmd.Run(); err != nil { + log.Printf("Failed to open homepage: %s", err.Error()) } }