2021-12-15 22:43:58 +08:00
|
|
|
package bug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
2022-02-09 17:22:52 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
|
2021-12-15 22:43:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
windows = "windows"
|
|
|
|
darwin = "darwin"
|
|
|
|
|
|
|
|
windowsOpen = "start"
|
|
|
|
darwinOpen = "open"
|
|
|
|
linuxOpen = "xdg-open"
|
|
|
|
|
|
|
|
os = "OS"
|
|
|
|
arch = "ARCH"
|
|
|
|
goctlVersion = "GOCTL_VERSION"
|
2021-12-15 23:24:32 +08:00
|
|
|
goVersion = "GO_VERSION"
|
2021-12-15 22:43:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var openCmd = map[string]string{
|
|
|
|
windows: windowsOpen,
|
|
|
|
darwin: darwinOpen,
|
|
|
|
}
|
|
|
|
|
|
|
|
func Action(_ *cli.Context) error {
|
|
|
|
env := getEnv()
|
2021-12-15 23:24:32 +08:00
|
|
|
content := fmt.Sprintf(issueTemplate, version.BuildVersion, env.string())
|
2021-12-15 22:43:58 +08:00
|
|
|
content = url.QueryEscape(content)
|
2021-12-15 23:24:32 +08:00
|
|
|
url := fmt.Sprintf("https://github.com/zeromicro/go-zero/issues/new?body=%s", content)
|
2021-12-15 22:43:58 +08:00
|
|
|
|
|
|
|
goos := runtime.GOOS
|
|
|
|
var cmd string
|
|
|
|
var args []string
|
|
|
|
cmd, ok := openCmd[goos]
|
|
|
|
if !ok {
|
|
|
|
cmd = linuxOpen
|
|
|
|
}
|
|
|
|
if goos == windows {
|
|
|
|
args = []string{"/c", "start"}
|
|
|
|
}
|
|
|
|
|
|
|
|
args = append(args, url)
|
|
|
|
return exec.Command(cmd, args...).Start()
|
|
|
|
}
|