From 7232d62a654bfc3fd57fc99fc89e429f82b18d7a Mon Sep 17 00:00:00 2001 From: Thomas Chaplin Date: Tue, 2 Mar 2021 13:48:57 +0000 Subject: [PATCH] improve openLinkInBrowser to support windows/linux/darwin (#3) --- main.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7a2f939..7346f89 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "runtime" "strings" "github.com/Songmu/prompter" @@ -29,9 +30,25 @@ type knownIssuesWorkflowInputSchema struct { } func openLinkInBrowser(link string) { - color.Green(fmt.Sprintf("Your new ticket has been successfully created! The link is %s \nWe will now try to open the new ticket for you in the browser. (Probably doesn't work on Windows.)", link)) - cmd := exec.Command("open", link) - cmd.Run() + color.Green(fmt.Sprintf("Your new ticket has been successfully created! The link is %s \nWe will now try to open the new ticket for you in the browser.", link)) + os := runtime.GOOS + switch os { + case "windows": + cmd := exec.Command("start", link) + cmd.Run() + case "darwin": + cmd := exec.Command("open", link) + cmd.Run() + case "linux": + _, err := exec.Command("which xdg-open").Output() + if err != nil { + color.Red(fmt.Sprintf("Unable to open link, please install xdg-open.")) + } + cmd := exec.Command("xdg-open", link) + cmd.Run() + default: + color.Red(fmt.Sprintf("Unable to open link for unsupported OS '%s'.\n", os)) + } } type cliArgs struct {