Skip to content

Commit

Permalink
fix: Use platform-specific open commands to run login url in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Nov 27, 2023
1 parent 06ed38b commit 82b0590
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 1 addition & 3 deletions internal/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -193,8 +192,7 @@ func Run(ctx context.Context, stdout *os.File, params RunParams) error {
if params.OpenBrowser {
fmt.Fprintf(stdout, "Here is your login link in case browser did not open %s\n\n", utils.Bold(createLoginSessionUrl))

openCmd := exec.CommandContext(ctx, "open", createLoginSessionUrl)
if err := openCmd.Run(); err != nil {
if err := RunOpenCmd(ctx, createLoginSessionUrl); err != nil {
return fmt.Errorf("cannot open default browser: %w", err)
}
} else {
Expand Down
13 changes: 13 additions & 0 deletions internal/login/login_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build darwin

package login

import (
"context"
"os/exec"
)

func RunOpenCmd(ctx context.Context, input string) error {
cmd := exec.CommandContext(ctx, "open", input)
return cmd.Run()
}
15 changes: 15 additions & 0 deletions internal/login/login_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build windows

package login

import (
"context"
"os"
"os/exec"
"path/filepath"
)

func RunOpenCmd(ctx context.Context, input string) error {
cmd := exec.CommandContext(ctx, filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe"), "url.dll,FileProtocolHandler", input)
return cmd.Run()
}
13 changes: 13 additions & 0 deletions internal/login/login_xdg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows && !darwin

package login

import (
"context"
"os/exec"
)

func RunOpenCmd(ctx context.Context, input string) error {
cmd := exec.CommandContext(ctx, "xdg-open", input)
return cmd.Run()
}

0 comments on commit 82b0590

Please sign in to comment.