Feat goctl bug (#1332)

* Support goctl bug

* fix typo

* format code

Co-authored-by: anqiansong <anqiansong@bytedance.com>
master
anqiansong 3 years ago committed by GitHub
parent 3d8ad5e4f6
commit 0b17e0e5d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,49 @@
package bug
import (
"fmt"
"net/url"
"os/exec"
"runtime"
"github.com/urfave/cli"
)
const (
windows = "windows"
darwin = "darwin"
windowsOpen = "start"
darwinOpen = "open"
linuxOpen = "xdg-open"
os = "OS"
arch = "ARCH"
goctlVersion = "GOCTL_VERSION"
)
var openCmd = map[string]string{
windows: windowsOpen,
darwin: darwinOpen,
}
func Action(_ *cli.Context) error {
env := getEnv()
content := fmt.Sprintf(issueTemplate, "<pre>\n"+env.string()+"</pre>")
content = url.QueryEscape(content)
url := fmt.Sprintf("https://github.com/zeromicro/go-zero/issues/new?title=TODO&body=%s", content)
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()
}

@ -0,0 +1,32 @@
package bug
import (
"bytes"
"fmt"
"runtime"
"github.com/tal-tech/go-zero/tools/goctl/internal/version"
)
type env map[string]string
func (e env) string() string {
if e == nil {
return ""
}
w := bytes.NewBuffer(nil)
for k, v := range e {
w.WriteString(fmt.Sprintf("%s = %q\n", k, v))
}
return w.String()
}
func getEnv() env {
e := make(env)
e[os] = runtime.GOOS
e[arch] = runtime.GOARCH
e[goctlVersion] = version.BuildVersion
return e
}

@ -0,0 +1,39 @@
package bug
const issueTemplate=`
<!-- Please submit an issue order by the following template. Thanks! -->
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
**To Reproduce**
<!-- Steps to reproduce the behavior, if applicable: -->
1. The code is
<pre>
</pre>
2. The error is
<pre>
</pre>
**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
**Screenshots**
<!-- If applicable, add screenshots to help explain your problem. -->
**Environments (please complete the following information):**
<!-- - OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional] -->
%s
**More description**
<!-- Add any other context about the problem here. -->
`

@ -18,6 +18,7 @@ import (
"github.com/tal-tech/go-zero/tools/goctl/api/new" "github.com/tal-tech/go-zero/tools/goctl/api/new"
"github.com/tal-tech/go-zero/tools/goctl/api/tsgen" "github.com/tal-tech/go-zero/tools/goctl/api/tsgen"
"github.com/tal-tech/go-zero/tools/goctl/api/validate" "github.com/tal-tech/go-zero/tools/goctl/api/validate"
"github.com/tal-tech/go-zero/tools/goctl/bug"
"github.com/tal-tech/go-zero/tools/goctl/docker" "github.com/tal-tech/go-zero/tools/goctl/docker"
"github.com/tal-tech/go-zero/tools/goctl/internal/errorx" "github.com/tal-tech/go-zero/tools/goctl/internal/errorx"
"github.com/tal-tech/go-zero/tools/goctl/internal/version" "github.com/tal-tech/go-zero/tools/goctl/internal/version"
@ -34,6 +35,11 @@ import (
const codeFailure = 1 const codeFailure = 1
var commands = []cli.Command{ var commands = []cli.Command{
{
Name: "bug",
Usage: "report a bug",
Action: bug.Action,
},
{ {
Name: "upgrade", Name: "upgrade",
Usage: "upgrade goctl to latest version", Usage: "upgrade goctl to latest version",

Loading…
Cancel
Save