openWithSystem opens a file or URL with the system's default application
(path string)
| 27 | |
| 28 | // openWithSystem opens a file or URL with the system's default application |
| 29 | func openWithSystem(path string) error { |
| 30 | var cmd *exec.Cmd |
| 31 | switch runtime.GOOS { |
| 32 | case "darwin": |
| 33 | cmd = exec.Command("open", path) |
| 34 | case "windows": |
| 35 | cmd = exec.Command("cmd", "/c", "start", "", path) |
| 36 | default: // linux and others |
| 37 | cmd = exec.Command("xdg-open", path) |
| 38 | } |
| 39 | err := cmd.Start() |
| 40 | if err == nil { |
| 41 | go func() { |
| 42 | _ = cmd.Wait() |
| 43 | }() |
| 44 | } |
| 45 | return err |
| 46 | } |
no test coverage detected