bug.go 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package bug
  2. import (
  3. "fmt"
  4. "net/url"
  5. "os/exec"
  6. "runtime"
  7. "github.com/urfave/cli"
  8. )
  9. const (
  10. windows = "windows"
  11. darwin = "darwin"
  12. windowsOpen = "start"
  13. darwinOpen = "open"
  14. linuxOpen = "xdg-open"
  15. os = "OS"
  16. arch = "ARCH"
  17. goctlVersion = "GOCTL_VERSION"
  18. )
  19. var openCmd = map[string]string{
  20. windows: windowsOpen,
  21. darwin: darwinOpen,
  22. }
  23. func Action(_ *cli.Context) error {
  24. env := getEnv()
  25. content := fmt.Sprintf(issueTemplate, "<pre>\n"+env.string()+"</pre>")
  26. content = url.QueryEscape(content)
  27. url := fmt.Sprintf("https://github.com/zeromicro/go-zero/issues/new?title=TODO&body=%s", content)
  28. goos := runtime.GOOS
  29. var cmd string
  30. var args []string
  31. cmd, ok := openCmd[goos]
  32. if !ok {
  33. cmd = linuxOpen
  34. }
  35. if goos == windows {
  36. args = []string{"/c", "start"}
  37. }
  38. args = append(args, url)
  39. return exec.Command(cmd, args...).Start()
  40. }