Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/microcks/microcks-cli/pkg/config"
"github.com/microcks/microcks-cli/pkg/connectors"
"github.com/microcks/microcks-cli/pkg/errors"
"github.com/microcks/microcks-cli/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -17,6 +18,7 @@ func NewStartCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command
imageName string
autoRemove bool
driver string
launchBrowser bool
)
var startCmd = &cobra.Command{
Use: "start",
Expand Down Expand Up @@ -141,12 +143,14 @@ microcks start --name [name of you container/instance]`,
errors.CheckError(err)

fmt.Printf("Microcks started successfully at %s\n", server)
util.LaunchBrowser(server, launchBrowser)
},
}
startCmd.Flags().StringVar(&name, "name", "microcks", "name for you microcks instance")
startCmd.Flags().StringVar(&hostPort, "port", "8585", "")
startCmd.Flags().StringVar(&imageName, "image", "quay.io/microcks/microcks-uber:latest-native", "image which will be used to create a container")
startCmd.Flags().BoolVar(&autoRemove, "rm", false, "mimic of '--rm' flag of dokcer to automatically remove the container when it exits")
startCmd.Flags().StringVar(&driver, "driver", "docker", "use --driver to change driver from docker to podman")
startCmd.Flags().BoolVar(&launchBrowser, "launch-browser", true, "Automatically launch browser to the Microcks dashboard")
return startCmd
}
35 changes: 35 additions & 0 deletions pkg/util/browser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package util

import (
"fmt"
"os"

"github.com/skratchdot/open-golang/open"
)

/*
LaunchBrowser opens the default system browser to the specified URL if conditions are met.
It skips opening the browser if the launchBrowser flag is false, if running in a CI environment,
or if the MICROCKS_NO_BROWSER environment variable is set.
*/
func LaunchBrowser(url string, launchBrowser bool) {
if !launchBrowser {
return
}

if os.Getenv("CI") != "" {
//if in CI environment, do not attempt to open browser
return
}

if os.Getenv("MICROCKS_NO_BROWSER") != "" {
// if MICROCKS_NO_BROWSER environment variable is set, do not attempt to open browser
return
}

fmt.Printf("Opening system default browser for %s\n", url)
err := open.Start(url)
if err != nil {
fmt.Printf("Failed to open browser: %v\n", err)
}
}