LaunchURL attempts to open the provided url in the user's default browser. It is platform dependent and it uses: - "open" on macOS - "rundll32" on Windows - "xdg-open" on everything else (Linux, FreeBSD, etc.)
(url string)
| 18 | // - "rundll32" on Windows |
| 19 | // - "xdg-open" on everything else (Linux, FreeBSD, etc.) |
| 20 | func LaunchURL(url string) error { |
| 21 | if err := is.URL.Validate(url); err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | switch runtime.GOOS { |
| 26 | case "darwin": |
| 27 | return exec.Command("open", url).Start() |
| 28 | case "windows": |
| 29 | // not sure if this is the best command but seems to be the most reliable based on the comments in |
| 30 | // https://stackoverflow.com/questions/3739327/launching-a-website-via-the-windows-commandline#answer-49115945 |
| 31 | return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() |
| 32 | default: |
| 33 | return exec.Command("xdg-open", url).Start() |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // YesNoPrompt performs a console prompt that asks the user for Yes/No answer. |
| 38 | // |
no test coverage detected
searching dependent graphs…