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
func parseMetaGoImports(r io.Reader) ([]metaImport, error) {
panic("unreachable")
}
func queryEscape(s string) string { panic("unreachable") }
func openBrowser(url string) bool { panic("unreachable") }
......@@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os/exec"
"runtime"
......@@ -29,31 +30,57 @@ func init() {
}
func runBug(cmd *Command, args []string) {
inspectGoVersion()
fmt.Println("```")
fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
var buf bytes.Buffer
buf.WriteString(bugHeader)
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() {
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 {
case "darwin":
printCmdOut("uname -v: ", "uname", "-v")
printCmdOut("", "sw_vers")
printCmdOut(w, "uname -v: ", "uname", "-v")
printCmdOut(w, "", "sw_vers")
case "linux":
printCmdOut("uname -sr: ", "uname", "-sr")
printCmdOut("libc:", "/lib/libc.so.6")
printCmdOut(w, "uname -sr: ", "uname", "-sr")
printCmdOut(w, "libc:", "/lib/libc.so.6")
case "openbsd", "netbsd", "freebsd", "dragonfly":
printCmdOut("uname -v: ", "uname", "-v")
printCmdOut(w, "uname -v: ", "uname", "-v")
case "solaris":
out, err := ioutil.ReadFile("/etc/release")
if err == nil {
fmt.Printf("/etc/release: %s\n", out)
fmt.Fprintf(w, "/etc/release: %s\n", out)
} else {
if buildV {
fmt.Printf("failed to read /etc/release: %v\n", err)
......@@ -62,8 +89,8 @@ func printOSDetails() {
}
}
func printCDetails() {
printCmdOut("lldb --version: ", "lldb", "--version")
func printCDetails(w io.Writer) {
printCmdOut(w, "lldb --version: ", "lldb", "--version")
cmd := exec.Command("gdb", "--version")
out, err := cmd.Output()
if err == nil {
......@@ -73,7 +100,7 @@ func printCDetails() {
idx := bytes.Index(out, []byte{'\n'})
line := out[:idx]
line = bytes.TrimSpace(line)
fmt.Printf("gdb --version: %s\n", line)
fmt.Fprintf(w, "gdb --version: %s\n", line)
} else {
if buildV {
fmt.Printf("failed to run gdb --version: %v\n", err)
......@@ -81,7 +108,7 @@ func printCDetails() {
}
}
func inspectGoVersion() {
func inspectGoVersion(w io.Writer) {
data, err := httpGET("https://golang.org/VERSION?m=text")
if err != nil {
if buildV {
......@@ -102,12 +129,12 @@ func inspectGoVersion() {
}
// 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.
// 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...)
out, err := cmd.Output()
if err != nil {
......@@ -116,5 +143,5 @@ func printCmdOut(prefix, path string, args ...string) {
}
return
}
fmt.Printf("%s%s\n", prefix, bytes.TrimSpace(out))
fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
}
......@@ -12,6 +12,7 @@
package main
import (
"cmd/internal/browser"
"crypto/tls"
"fmt"
"io"
......@@ -113,3 +114,6 @@ func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body
}
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