Skip to content

Commit 2fc49ea

Browse files
ashishra0Ashish Raotibotiber
authored andcommitted
cli: add browser flag to console command (close hasura#3333) (hasura#3601)
Co-authored-by: Ashish Rao <ashishrao@hasura.io> Co-authored-by: Thibaut Tiberghien <thibaut@smplrspace.com>
1 parent 2aba7ed commit 2fc49ea

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎cli/cli.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import (
1515
"path/filepath"
1616
"time"
1717

18-
"github.com/hasura/graphql-engine/cli/telemetry"
19-
"github.com/hasura/graphql-engine/cli/util"
20-
2118
"github.com/briandowns/spinner"
2219
"github.com/gofrs/uuid"
20+
"github.com/hasura/graphql-engine/cli/telemetry"
21+
"github.com/hasura/graphql-engine/cli/util"
2322
"github.com/hasura/graphql-engine/cli/version"
2423
"github.com/mattn/go-colorable"
2524
"github.com/pkg/errors"

‎cli/commands/console.go‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewConsoleCmd(ec *cli.ExecutionContext) *cobra.Command {
6060
f.StringVar(&opts.Address, "address", "localhost", "address to serve console and migration API from")
6161
f.BoolVar(&opts.DontOpenBrowser, "no-browser", false, "do not automatically open console in browser")
6262
f.StringVar(&opts.StaticDir, "static-dir", "", "directory where static assets mentioned in the console html template can be served from")
63+
f.StringVar(&opts.Browser, "browser", "", "open console in a specific browser")
6364

6465
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
6566
f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine")
@@ -85,6 +86,7 @@ type consoleOptions struct {
8586
WG *sync.WaitGroup
8687

8788
StaticDir string
89+
Browser string
8890
}
8991

9092
func (o *consoleOptions) run() error {
@@ -166,12 +168,21 @@ func (o *consoleOptions) run() error {
166168
consoleURL := fmt.Sprintf("http://%s:%s/", o.Address, o.ConsolePort)
167169

168170
if !o.DontOpenBrowser {
169-
o.EC.Spin(color.CyanString("Opening console using default browser..."))
170-
defer o.EC.Spinner.Stop()
171+
if o.Browser != "" {
172+
o.EC.Spin(color.CyanString("Opening console on: %s", o.Browser))
173+
defer o.EC.Spinner.Stop()
174+
err = open.RunWith(consoleURL, o.Browser)
175+
if err != nil {
176+
o.EC.Logger.WithError(err).Warnf("failed opening console in '%s', try to open the url manually", o.Browser)
177+
}
178+
} else {
179+
o.EC.Spin(color.CyanString("Opening console using default browser..."))
180+
defer o.EC.Spinner.Stop()
171181

172-
err = open.Run(consoleURL)
173-
if err != nil {
174-
o.EC.Logger.WithError(err).Warn("Error opening browser, try to open the url manually?")
182+
err = open.Run(consoleURL)
183+
if err != nil {
184+
o.EC.Logger.WithError(err).Warn("Error opening browser, try to open the url manually?")
185+
}
175186
}
176187
}
177188

‎cli/commands/migrate_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"testing"
1515

1616
"github.com/Masterminds/semver"
17-
1817
mt "github.com/hasura/graphql-engine/cli/migrate/testing"
1918
"github.com/hasura/graphql-engine/cli/version"
2019
_ "github.com/lib/pq"

0 commit comments

Comments
 (0)