]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: make bug subcommand open the browser
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 14 Sep 2016 21:51:41 +0000 (14:51 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Sep 2016 12:33:53 +0000 (12:33 +0000)
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: Robert Griesemer <gri@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/bootstrap.go
src/cmd/go/bug.go
src/cmd/go/http.go

index caa96769d841a5a9ff1528196ca43ea3e13a7d3b..2148d12685a184724a290709c9f2f6ce714119c8 100644 (file)
@@ -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") }
index 7cf39ecd845e2490243bfeea9ef2d67fca23e44f..b6d8e35b5a98fc7eef094e08c34fbbec9b47777c 100644 (file)
@@ -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))
 }
index 05ea50304998d6bebf89f13d29310634f1054ee3..1dc2c12c64edafe300df06eadd3ba3754a6bf2cb 100644 (file)
@@ -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) }