Skip to content

Commit

Permalink
improve openLinkInBrowser to support windows/linux/darwin (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaschaplin authored Mar 2, 2021
1 parent 7e1f5d2 commit 7232d62
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"os/exec"
"runtime"
"strings"

"github.com/Songmu/prompter"
Expand All @@ -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 {
Expand Down

0 comments on commit 7232d62

Please sign in to comment.