From 31e089c7ee9520ad149a0dd135361c953b8450ee Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 29 Nov 2022 17:12:11 +0100 Subject: [PATCH] requested changes per #334 --- framework/framework.go | 7 +++---- internal/cli/cli.go | 2 +- internal/cli/run/run.go | 16 ++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/framework/framework.go b/framework/framework.go index 003c9e194..a86ab4df7 100644 --- a/framework/framework.go +++ b/framework/framework.go @@ -4,10 +4,9 @@ import "io" // Flag is used by many of the framework generators type Flag struct { - Embed bool - Minify bool - Hot bool - Noautolaunch bool + Embed bool + Minify bool + Hot bool // Comes from *bud.Input Stdin io.Reader diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 2b366385b..cd15fe437 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -63,7 +63,7 @@ func (c *CLI) Run(ctx context.Context, args ...string) error { cli.Flag("embed", "embed assets").Bool(&cmd.Flag.Embed).Default(false) cli.Flag("hot", "hot reloading").Bool(&cmd.Flag.Hot).Default(true) cli.Flag("minify", "minify assets").Bool(&cmd.Flag.Minify).Default(false) - cli.Flag("noautolaunch", "don't autolaunch browser").Bool(&cmd.Flag.Noautolaunch).Default(false) + cli.Flag("open", "open browser on dev server startup").Bool(&cmd.OpenBrowser).Default(false) cli.Flag("listen", "address to listen to").String(&cmd.Listen).Default(":3000") cli.Run(cmd.Run) } diff --git a/internal/cli/run/run.go b/internal/cli/run/run.go index 2eec0cb45..ce9bbc53a 100644 --- a/internal/cli/run/run.go +++ b/internal/cli/run/run.go @@ -48,8 +48,9 @@ type Command struct { in *bud.Input // Flags - Flag *framework.Flag - Listen string // Web listener address + Flag *framework.Flag + Listen string // Web listener address + OpenBrowser bool } // Run the run command. That's a mouthful. @@ -151,12 +152,11 @@ func (c *Command) Run(ctx context.Context) (err error) { eg.Go(func() error { return appServer.Run(ctx) }) // Wait until either the hot or web server exits - // Launch browser unless we're told not to - if !c.Flag.Noautolaunch { // if not not autolaunch, i.e. if autolaunch - go func() { - time.Sleep(1 * time.Second) - _ = browser.OpenURL("http://" + webln.Addr().String()) - }() + if !c.Flag.OpenBrowser { + err := browser.OpenURL("http://" + webln.Addr().String()) + if err != nil { + return err + } } err = eg.Wait()