OpenInBrowser opens the given url on a web browser
(url, browser string)
| 101 | |
| 102 | // OpenInBrowser opens the given url on a web browser |
| 103 | func OpenInBrowser(url, browser string) error { |
| 104 | var cmd *exec.Cmd |
| 105 | switch runtime.GOOS { |
| 106 | case "darwin": |
| 107 | if browser == "" { |
| 108 | cmd = exec.Command("open", url) |
| 109 | } else { |
| 110 | cmd = exec.Command("open", "-a", browser, url) |
| 111 | } |
| 112 | case "linux": |
| 113 | if IsWSL() { |
| 114 | cmd = exec.Command("rundll32.exe", "url.dll,FileProtocolHandler", url) |
| 115 | } else { |
| 116 | cmd = exec.Command("xdg-open", url) |
| 117 | } |
| 118 | case "android": |
| 119 | cmd = exec.Command("xdg-open", url) |
| 120 | case "windows": |
| 121 | cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url) |
| 122 | default: |
| 123 | return errors.Errorf("unsupported platform '%s'", runtime.GOOS) |
| 124 | } |
| 125 | |
| 126 | return errors.WithStack(cmd.Start()) |
| 127 | } |
| 128 | |
| 129 | // Step executes step with the given commands and returns the standard output. |
| 130 | func Step(args ...string) ([]byte, error) { |
no test coverage detected
searching dependent graphs…