diff --git a/internal/browser/browser.go b/internal/browser/browser.go index 12d9f85..0dad815 100644 --- a/internal/browser/browser.go +++ b/internal/browser/browser.go @@ -29,10 +29,9 @@ type Opener interface { type StderrPrint struct{} func openURL(url string) error { - var err error switch runtime.GOOS { case "darwin": // macOS - err = exec.Command("open", url).Start() + return exec.Command("open", url).Run() case "linux": providers := []string{"xdg-open", "x-www-browser", "www-browser"} @@ -40,22 +39,28 @@ func openURL(url string) error { // One of them is xdg-open, another is x-www-browser, then there's www-browser, etc. // Look for one that exists and run it for _, provider := range providers { - if _, err := exec.LookPath(provider); err == nil { - err = exec.Command(provider, url).Start() + if bin_path, err := exec.LookPath(provider); err == nil { + err = exec.Command(bin_path, url).Run() + if err == nil { + return nil + } } } + return fmt.Errorf("unsupported platform") case "windows": - err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() + return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Run() default: - err = fmt.Errorf("unsupported platform") + return fmt.Errorf("unsupported platform") } - return err } func (p *StderrPrint) Open(u *url.URL) error { fmt.Fprintf( - os.Stdout, - "Opening the following URL in your web browser to authenticate:\n\n\t%s\n\n", + os.Stderr, + `Attempting to automaticaly open the authentication URL in your web browser. +If the browser does not open or you wish to use a different device to authorize this request, open the following URL: + %s +`, u, ) openURL(u.String())