Feat goctl bug (#1332)
* Support goctl bug * fix typo * format code Co-authored-by: anqiansong <anqiansong@bytedance.com>master
parent
3d8ad5e4f6
commit
0b17e0e5d9
@ -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. -->
|
||||
|
||||
`
|
Loading…
Reference in New Issue