Commit 896ac677 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder Committed by Brad Fitzpatrick

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 <josharian@gmail.com>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
Reviewed-by: default avatarMinux Ma <minux@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 27eebbab
...@@ -36,3 +36,6 @@ func httpsOrHTTP(importPath string, security securityMode) (string, io.ReadClose ...@@ -36,3 +36,6 @@ func httpsOrHTTP(importPath string, security securityMode) (string, io.ReadClose
func parseMetaGoImports(r io.Reader) ([]metaImport, error) { func parseMetaGoImports(r io.Reader) ([]metaImport, error) {
panic("unreachable") panic("unreachable")
} }
func queryEscape(s string) string { panic("unreachable") }
func openBrowser(url string) bool { panic("unreachable") }
...@@ -7,6 +7,7 @@ package main ...@@ -7,6 +7,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os/exec" "os/exec"
"runtime" "runtime"
...@@ -29,31 +30,57 @@ func init() { ...@@ -29,31 +30,57 @@ func init() {
} }
func runBug(cmd *Command, args []string) { func runBug(cmd *Command, args []string) {
inspectGoVersion() var buf bytes.Buffer
fmt.Println("```") buf.WriteString(bugHeader)
fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) inspectGoVersion(&buf)
fmt.Fprint(&buf, "#### System details\n\n")
fmt.Fprintln(&buf, "```")
fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
for _, e := range mkEnv() { for _, e := range mkEnv() {
fmt.Printf("%s=\"%s\"\n", e.name, e.value) fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value)
}
printOSDetails(&buf)
printCDetails(&buf)
fmt.Fprintln(&buf, "```")
body := buf.String()
url := "https://github.com/golang/go/issues/new?body=" + queryEscape(body)
if !openBrowser(url) {
fmt.Print("Please file a new issue at golang.org/issue/new using this template:\n\n")
fmt.Print(body)
} }
printOSDetails()
printCDetails()
fmt.Println("```")
} }
func printOSDetails() { const bugHeader = `Please answer these questions before submitting your issue. Thanks!
#### What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
#### What did you expect to see?
#### What did you see instead?
`
func printOSDetails(w io.Writer) {
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case "darwin":
printCmdOut("uname -v: ", "uname", "-v") printCmdOut(w, "uname -v: ", "uname", "-v")
printCmdOut("", "sw_vers") printCmdOut(w, "", "sw_vers")
case "linux": case "linux":
printCmdOut("uname -sr: ", "uname", "-sr") printCmdOut(w, "uname -sr: ", "uname", "-sr")
printCmdOut("libc:", "/lib/libc.so.6") printCmdOut(w, "libc:", "/lib/libc.so.6")
case "openbsd", "netbsd", "freebsd", "dragonfly": case "openbsd", "netbsd", "freebsd", "dragonfly":
printCmdOut("uname -v: ", "uname", "-v") printCmdOut(w, "uname -v: ", "uname", "-v")
case "solaris": case "solaris":
out, err := ioutil.ReadFile("/etc/release") out, err := ioutil.ReadFile("/etc/release")
if err == nil { if err == nil {
fmt.Printf("/etc/release: %s\n", out) fmt.Fprintf(w, "/etc/release: %s\n", out)
} else { } else {
if buildV { if buildV {
fmt.Printf("failed to read /etc/release: %v\n", err) fmt.Printf("failed to read /etc/release: %v\n", err)
...@@ -62,8 +89,8 @@ func printOSDetails() { ...@@ -62,8 +89,8 @@ func printOSDetails() {
} }
} }
func printCDetails() { func printCDetails(w io.Writer) {
printCmdOut("lldb --version: ", "lldb", "--version") printCmdOut(w, "lldb --version: ", "lldb", "--version")
cmd := exec.Command("gdb", "--version") cmd := exec.Command("gdb", "--version")
out, err := cmd.Output() out, err := cmd.Output()
if err == nil { if err == nil {
...@@ -73,7 +100,7 @@ func printCDetails() { ...@@ -73,7 +100,7 @@ func printCDetails() {
idx := bytes.Index(out, []byte{'\n'}) idx := bytes.Index(out, []byte{'\n'})
line := out[:idx] line := out[:idx]
line = bytes.TrimSpace(line) line = bytes.TrimSpace(line)
fmt.Printf("gdb --version: %s\n", line) fmt.Fprintf(w, "gdb --version: %s\n", line)
} else { } else {
if buildV { if buildV {
fmt.Printf("failed to run gdb --version: %v\n", err) fmt.Printf("failed to run gdb --version: %v\n", err)
...@@ -81,7 +108,7 @@ func printCDetails() { ...@@ -81,7 +108,7 @@ func printCDetails() {
} }
} }
func inspectGoVersion() { func inspectGoVersion(w io.Writer) {
data, err := httpGET("https://golang.org/VERSION?m=text") data, err := httpGET("https://golang.org/VERSION?m=text")
if err != nil { if err != nil {
if buildV { if buildV {
...@@ -102,12 +129,12 @@ func inspectGoVersion() { ...@@ -102,12 +129,12 @@ func inspectGoVersion() {
} }
// Devel version or outdated release. Either way, this request is apropos. // Devel version or outdated release. Either way, this request is apropos.
fmt.Printf("Please check whether the issue also reproduces on the latest release, %s.\n\n", release) fmt.Fprintf(w, "#### Does this issue reproduce with the latest release (%s)?\n\n\n", release)
} }
// printCmdOut prints the output of running the given command. // printCmdOut prints the output of running the given command.
// It ignores failures; 'go bug' is best effort. // It ignores failures; 'go bug' is best effort.
func printCmdOut(prefix, path string, args ...string) { func printCmdOut(w io.Writer, prefix, path string, args ...string) {
cmd := exec.Command(path, args...) cmd := exec.Command(path, args...)
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
...@@ -116,5 +143,5 @@ func printCmdOut(prefix, path string, args ...string) { ...@@ -116,5 +143,5 @@ func printCmdOut(prefix, path string, args ...string) {
} }
return return
} }
fmt.Printf("%s%s\n", prefix, bytes.TrimSpace(out)) fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
package main package main
import ( import (
"cmd/internal/browser"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io" "io"
...@@ -113,3 +114,6 @@ func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body ...@@ -113,3 +114,6 @@ func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body
} }
return urlStr, res.Body, nil return urlStr, res.Body, nil
} }
func queryEscape(s string) string { return url.QueryEscape(s) }
func openBrowser(url string) bool { return browser.Open(url) }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment