Skip to content

Commit 896ac67

Browse files
josharianbradfitz
authored andcommitted
cmd/go: make bug subcommand open the browser
Instead of dumping information for the use to copy/paste into the issue tracker, open the issue tracker directly with a pre-filled template. Change-Id: I370d0063b609200497014ccda35244fa4314a662 Reviewed-on: https://go-review.googlesource.com/29210 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Minux Ma <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 27eebba commit 896ac67

3 files changed

Lines changed: 55 additions & 21 deletions

File tree

src/cmd/go/bootstrap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ func httpsOrHTTP(importPath string, security securityMode) (string, io.ReadClose
3636
func parseMetaGoImports(r io.Reader) ([]metaImport, error) {
3737
panic("unreachable")
3838
}
39+
40+
func queryEscape(s string) string { panic("unreachable") }
41+
func openBrowser(url string) bool { panic("unreachable") }

src/cmd/go/bug.go

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
import (
88
"bytes"
99
"fmt"
10+
"io"
1011
"io/ioutil"
1112
"os/exec"
1213
"runtime"
@@ -29,31 +30,57 @@ func init() {
2930
}
3031

3132
func runBug(cmd *Command, args []string) {
32-
inspectGoVersion()
33-
fmt.Println("```")
34-
fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
33+
var buf bytes.Buffer
34+
buf.WriteString(bugHeader)
35+
inspectGoVersion(&buf)
36+
fmt.Fprint(&buf, "#### System details\n\n")
37+
fmt.Fprintln(&buf, "```")
38+
fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
3539
for _, e := range mkEnv() {
36-
fmt.Printf("%s=\"%s\"\n", e.name, e.value)
40+
fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value)
41+
}
42+
printOSDetails(&buf)
43+
printCDetails(&buf)
44+
fmt.Fprintln(&buf, "```")
45+
46+
body := buf.String()
47+
url := "https://github.com/golang/go/issues/new?body=" + queryEscape(body)
48+
if !openBrowser(url) {
49+
fmt.Print("Please file a new issue at golang.org/issue/new using this template:\n\n")
50+
fmt.Print(body)
3751
}
38-
printOSDetails()
39-
printCDetails()
40-
fmt.Println("```")
4152
}
4253

43-
func printOSDetails() {
54+
const bugHeader = `Please answer these questions before submitting your issue. Thanks!
55+
56+
#### What did you do?
57+
If possible, provide a recipe for reproducing the error.
58+
A complete runnable program is good.
59+
A link on play.golang.org is best.
60+
61+
62+
#### What did you expect to see?
63+
64+
65+
#### What did you see instead?
66+
67+
68+
`
69+
70+
func printOSDetails(w io.Writer) {
4471
switch runtime.GOOS {
4572
case "darwin":
46-
printCmdOut("uname -v: ", "uname", "-v")
47-
printCmdOut("", "sw_vers")
73+
printCmdOut(w, "uname -v: ", "uname", "-v")
74+
printCmdOut(w, "", "sw_vers")
4875
case "linux":
49-
printCmdOut("uname -sr: ", "uname", "-sr")
50-
printCmdOut("libc:", "/lib/libc.so.6")
76+
printCmdOut(w, "uname -sr: ", "uname", "-sr")
77+
printCmdOut(w, "libc:", "/lib/libc.so.6")
5178
case "openbsd", "netbsd", "freebsd", "dragonfly":
52-
printCmdOut("uname -v: ", "uname", "-v")
79+
printCmdOut(w, "uname -v: ", "uname", "-v")
5380
case "solaris":
5481
out, err := ioutil.ReadFile("/etc/release")
5582
if err == nil {
56-
fmt.Printf("/etc/release: %s\n", out)
83+
fmt.Fprintf(w, "/etc/release: %s\n", out)
5784
} else {
5885
if buildV {
5986
fmt.Printf("failed to read /etc/release: %v\n", err)
@@ -62,8 +89,8 @@ func printOSDetails() {
6289
}
6390
}
6491

65-
func printCDetails() {
66-
printCmdOut("lldb --version: ", "lldb", "--version")
92+
func printCDetails(w io.Writer) {
93+
printCmdOut(w, "lldb --version: ", "lldb", "--version")
6794
cmd := exec.Command("gdb", "--version")
6895
out, err := cmd.Output()
6996
if err == nil {
@@ -73,15 +100,15 @@ func printCDetails() {
73100
idx := bytes.Index(out, []byte{'\n'})
74101
line := out[:idx]
75102
line = bytes.TrimSpace(line)
76-
fmt.Printf("gdb --version: %s\n", line)
103+
fmt.Fprintf(w, "gdb --version: %s\n", line)
77104
} else {
78105
if buildV {
79106
fmt.Printf("failed to run gdb --version: %v\n", err)
80107
}
81108
}
82109
}
83110

84-
func inspectGoVersion() {
111+
func inspectGoVersion(w io.Writer) {
85112
data, err := httpGET("https://golang.org/VERSION?m=text")
86113
if err != nil {
87114
if buildV {
@@ -102,12 +129,12 @@ func inspectGoVersion() {
102129
}
103130

104131
// Devel version or outdated release. Either way, this request is apropos.
105-
fmt.Printf("Please check whether the issue also reproduces on the latest release, %s.\n\n", release)
132+
fmt.Fprintf(w, "#### Does this issue reproduce with the latest release (%s)?\n\n\n", release)
106133
}
107134

108135
// printCmdOut prints the output of running the given command.
109136
// It ignores failures; 'go bug' is best effort.
110-
func printCmdOut(prefix, path string, args ...string) {
137+
func printCmdOut(w io.Writer, prefix, path string, args ...string) {
111138
cmd := exec.Command(path, args...)
112139
out, err := cmd.Output()
113140
if err != nil {
@@ -116,5 +143,5 @@ func printCmdOut(prefix, path string, args ...string) {
116143
}
117144
return
118145
}
119-
fmt.Printf("%s%s\n", prefix, bytes.TrimSpace(out))
146+
fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
120147
}

src/cmd/go/http.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package main
1313

1414
import (
15+
"cmd/internal/browser"
1516
"crypto/tls"
1617
"fmt"
1718
"io"
@@ -113,3 +114,6 @@ func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body
113114
}
114115
return urlStr, res.Body, nil
115116
}
117+
118+
func queryEscape(s string) string { return url.QueryEscape(s) }
119+
func openBrowser(url string) bool { return browser.Open(url) }

0 commit comments

Comments
 (0)