Przeglądaj źródła

Support opening a browser on startup

Lucas Stadler 9 lat temu
rodzic
commit
f4792688c0
1 zmienionych plików z 9 dodań i 1 usunięć
  1. 9 1
      go/linguaevalia/linguaevalia.go

+ 9 - 1
go/linguaevalia/linguaevalia.go

@ -18,6 +18,7 @@ import (
18 18
	"os/exec"
19 19
	"path"
20 20
	"strings"
21
	"time"
21 22
)
22 23
23 24
type Language interface {
@ -242,6 +243,7 @@ help		- Display this help message.
242 243
var language = flag.String("l", "", "The language to use for code passed via stdin.")
243 244
var host = flag.String("h", "localhost", "The host to listen on.")
244 245
var port = flag.Int("p", 8000, "The port to listen on.")
246
var openBrowser = flag.Bool("open", false, "Whether to open a browser with the server url.")
245 247
246 248
func main() {
247 249
	var cmd string
@ -253,7 +255,13 @@ func main() {
253 255
	flag.Parse()
254 256
255 257
	switch cmd {
256
	case "server":
258
	case "server", "-open":
259
		if *openBrowser {
260
			go func() {
261
				time.Sleep(100 * time.Millisecond)
262
				exec.Command("xdg-open", fmt.Sprintf("http://localhost:%d", *port)).Run()
263
			}()
264
		}
257 265
		runServer()
258 266
	case "run":
259 267
		runOnce(flag.Args())