From 6fe4d62a80e455c5717b8b0267b224079060ba5b Mon Sep 17 00:00:00 2001 From: alessio Date: Mon, 17 Oct 2016 11:44:45 +0200 Subject: [PATCH] cli options for open the web panel in browser --- app/main.go | 1 + realize.go | 2 ++ server/main.go | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/main.go b/app/main.go index 61ea2a4..9edfa4f 100644 --- a/app/main.go +++ b/app/main.go @@ -105,6 +105,7 @@ func (r *realize) Wdir() string { func (r *realize) Serve(p *cli.Context) { if !p.Bool("no-server") { + r.Server.Open = p.Bool("open") r.Server.Start() } } diff --git a/realize.go b/realize.go index bea8f7b..946cf65 100644 --- a/realize.go +++ b/realize.go @@ -30,6 +30,7 @@ func main() { Usage: "Build and watch file changes", Flags: []cli.Flag{ &cli.BoolFlag{Name: "no-server", Usage: "Enable the web panel"}, + &cli.BoolFlag{Name: "open", Usage: "Automatically opens the web panel"}, }, Action: func(p *cli.Context) error { return app.Handle(app.Run(p)) @@ -48,6 +49,7 @@ func main() { &cli.BoolFlag{Name: "no-bin", Usage: "Disables the installation"}, &cli.BoolFlag{Name: "no-fmt", Usage: "Disables the fmt (go fmt)"}, &cli.BoolFlag{Name: "no-server", Usage: "Disables the web panel"}, + &cli.BoolFlag{Name: "open", Usage: "Automatically opens the web panel"}, &cli.BoolFlag{Name: "test", Value: false, Usage: "Enables the tests"}, &cli.BoolFlag{Name: "config", Value: false, Usage: "Take the defined settings if exist a Configuration file."}, }, diff --git a/server/main.go b/server/main.go index 63c94a6..dd30e60 100644 --- a/server/main.go +++ b/server/main.go @@ -16,6 +16,7 @@ type Server struct { Blueprint *c.Blueprint Files map[string]string Sync chan string + Open bool } func render(c echo.Context, path string, mime int) error { @@ -82,7 +83,9 @@ func (s *Server) Start() { //e.GET("/ws", standard.WrapHandler(s.projects())) e.GET("/ws", standard.WrapHandler(s.projects())) go e.Run(standard.New(":5000")) - Open("http://localhost:5000") + if(s.Open) { + Open("http://localhost:5000") + } } // The WebSocket for projects list