Skip to content
Permalink
Browse files

add -o, --open to `up start` for opening in the browser

  • Loading branch information...
tj committed Feb 1, 2018
1 parent 983cfcf commit 0ba98ecb91e5d5960f28517f43765968c7b43266
Showing with 7 additions and 8 deletions.
  1. +7 −8 internal/cli/start/start.go
@@ -20,10 +20,12 @@ import (
func init() {
cmd := root.Command("start", "Start development server.")
cmd.Example(`up start`, "Start development server on port 3000.")
cmd.Example(`up start -o'`, "Start development server and open in the browser.")
cmd.Example(`up start --address :5000`, "Start development server on port 5000.")
cmd.Example(`up start -c 'go run main.go'`, "Override proxy command.")
command := cmd.Flag("command", "Proxy command override").Short('c').String()

command := cmd.Flag("command", "Proxy command override").Short('c').String()
open := cmd.Flag("open", "Open endpoint in the browser.").Short('o').Bool()
addr := cmd.Flag("address", "Address for server.").Default(":3000").String()

cmd.Action(func(_ *kingpin.ParseContext) error {
@@ -65,7 +67,10 @@ func init() {
return errors.Wrap(err, "initializing handler")
}

open(*addr)
if *open {
_, port, _ := net.SplitHostPort(*addr)
browser.OpenURL(fmt.Sprintf("http://localhost:%s", port))
}

log.WithField("address", *addr).Info("listening")
if err := http.ListenAndServe(*addr, h); err != nil {
@@ -75,9 +80,3 @@ func init() {
return nil
})
}

// open addr in the browser.
func open(addr string) {
_, port, _ := net.SplitHostPort(addr)
browser.OpenURL(fmt.Sprintf("http://localhost:%s", port))
}

0 comments on commit 0ba98ec

Please sign in to comment.
You can’t perform that action at this time.