Skip to content

Commit

Permalink
replace custom browser launching with cli/browser
Browse files Browse the repository at this point in the history
  • Loading branch information
colesnodgrass committed May 6, 2024
1 parent c86099a commit db33708
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/airbytehq/abctl
go 1.21.9

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
31 changes: 2 additions & 29 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,33 +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)
case "linux":
if _, err := exec.LookPath("xdg-open"); err == nil {
cmd = exec.Command("xdg-open", url)
} else if _, err := exec.LookPath("sensible-browser"); err == nil {
cmd = exec.Command("sensible-browser", url)
} else if _, err := exec.LookPath("x-www-browser"); err == nil {
cmd = exec.Command("x-www-browser", url)
} else if _, err := exec.LookPath("gnome-open"); err == nil {
cmd = exec.Command("gnome-open", url)
} else if _, err := exec.LookPath("open"); err == nil {
cmd = exec.Command("open", url)
} else {
return errors.New("unable to determine executable to launch web-browser")
}

default:
return fmt.Errorf("unsupported platform '%s'", runtime.GOOS)
}
return cmd.Run()
}
c.launcher = browser.OpenURL
}

// fetch k8s version information
Expand Down

0 comments on commit db33708

Please sign in to comment.