Skip to content

Commit

Permalink
fix: improve linux web-browser code (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass authored May 7, 2024
1 parent 7909115 commit 4f8c4cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/airbytehq/abctl

go 1.21.9
go 1.22.2

require (
github.com/cli/browser v1.3.0
github.com/docker/docker v26.1.0+incompatible
github.com/google/go-cmp v0.6.0
github.com/mittwald/go-helm-client v0.12.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk=
github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
Expand Down
19 changes: 4 additions & 15 deletions internal/local/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/airbytehq/abctl/internal/local/k8s"
"github.com/airbytehq/abctl/internal/local/localerr"
"github.com/airbytehq/abctl/internal/telemetry"
"github.com/cli/browser"
helmclient "github.com/mittwald/go-helm-client"
"github.com/mittwald/go-helm-client/values"
"github.com/pterm/pterm"
Expand All @@ -23,9 +24,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -177,18 +176,7 @@ func New(provider k8s.Provider, portHTTP int, opts ...Option) (*Command, error)

// set the browser launcher, if not defined
if c.launcher == nil {
c.launcher = func(url string) error {
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("open", url)
case "windows":
cmd = exec.Command("cmd", "/c", "start", url)
default:
cmd = exec.Command("xdg-open", url)
}
return cmd.Run()
}
c.launcher = browser.OpenURL
}

// fetch k8s version information
Expand Down Expand Up @@ -504,7 +492,8 @@ func (c *Command) openBrowser(ctx context.Context, url string) error {
if err := c.launcher(url); err != nil {
pterm.Warning.Printfln("Failed to launch web-browser.\n"+
"Please launch your web-browser to access %s", url)
return fmt.Errorf("could not launch browser: %w", err)
pterm.Debug.Printfln("failed to launch web-browser: %s", err.Error())
// don't consider a failed web-browser to be a failed installation
}

pterm.Success.Println("Launched web-browser successfully")
Expand Down

0 comments on commit 4f8c4cc

Please sign in to comment.