cmd/geth: update bug with better infos

This commit is contained in:
Jeffrey Wilcke 2017-02-20 10:22:37 +01:00
parent 3e55dc6f2d
commit 626c1f74fb
2 changed files with 98 additions and 48 deletions

View file

@ -18,11 +18,15 @@ package main
import (
"bytes"
"html/template"
"fmt"
"io"
"io/ioutil"
"net/url"
"os/exec"
"runtime"
"strings"
"github.com/ethereum/go-ethereum/cmd/internal/browser"
"github.com/ethereum/go-ethereum/params"
cli "gopkg.in/urfave/cli.v1"
@ -39,30 +43,56 @@ var bugCommand = cli.Command{
// reportBug reports a bug by opening a new URL to the go-ethereum GH issue
// tracker and setting default values as the issue body.
func reportBug(ctx *cli.Context) error {
// compile the bug report template or crash
t := template.Must(template.New("bug-report").Parse(bugTemplate))
// assemble the info for the bug template
uname, err := uname()
if err != nil {
return err
}
info := struct {
Version, GoVersion, OS, Uname string
}{Version: params.Version, GoVersion: runtime.Version(), OS: runtime.GOOS, Uname: uname}
// execute template and write contents to buff
var buff bytes.Buffer
if err := t.Execute(&buff, info); err != nil {
return err
}
fmt.Fprintln(&buff, header)
fmt.Fprintln(&buff, "Version:", params.Version)
fmt.Fprintln(&buff, "Go Version:", runtime.Version())
fmt.Fprintln(&buff, "OS:", runtime.GOOS)
printOSDetails(&buff)
// open a new GH issue
return exec.Command("open", "https://github.com/ethereum/go-ethereum/issues/new?body="+url.QueryEscape(buff.String())).Start()
browser.Open("https://github.com/ethereum/go-ethereum/issues/new?body=" + url.QueryEscape(buff.String()))
return nil
}
const bugTemplate = `Please answer these questions before submitting your issue. Thanks!
// copied from the Go source. Copyright 2017 The Go Authors
func printOSDetails(w io.Writer) {
switch runtime.GOOS {
case "darwin":
printCmdOut(w, "uname -v: ", "uname", "-v")
printCmdOut(w, "", "sw_vers")
case "linux":
printCmdOut(w, "uname -sr: ", "uname", "-sr")
printCmdOut(w, "", "lsb_release", "-a")
case "openbsd", "netbsd", "freebsd", "dragonfly":
printCmdOut(w, "uname -v: ", "uname", "-v")
case "solaris":
out, err := ioutil.ReadFile("/etc/release")
if err == nil {
fmt.Fprintf(w, "/etc/release: %s\n", out)
} else {
fmt.Printf("failed to read /etc/release: %v\n", err)
}
}
}
// printCmdOut prints the output of running the given command.
// It ignores failures; 'go bug' is best effort.
//
// copied from the Go source. Copyright 2017 The Go Authors
func printCmdOut(w io.Writer, prefix, path string, args ...string) {
cmd := exec.Command(path, args...)
out, err := cmd.Output()
if err != nil {
fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err)
return
}
fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
}
const header = `Please answer these questions before submitting your issue. Thanks!
#### What did you do?
@ -71,30 +101,4 @@ const bugTemplate = `Please answer these questions before submitting your issue.
#### What did you see instead?
#### System details
Version: {{.Version}}
Go Version: {{.GoVersion}}
OS: {{.OS}}
uname -a: {{.Uname}}
`
// uname returns machine hardware, os release, name and version.
func uname() (string, error) {
// figure out the uname of the system (e.g. uname, systeminfo)
var (
err error
uname []byte
cmd = [2]string{"uname", "-a"}
)
if runtime.GOOS == "windows" {
cmd = [2]string{"systeminfo"}
}
uname, err = exec.Command(cmd[0], cmd[1]).Output()
if err != nil {
return "", err
}
return string(uname), err
}

View file

@ -0,0 +1,46 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package browser provides utilities for interacting with users' browsers.
package browser
import (
"os"
"os/exec"
"runtime"
)
// Commands returns a list of possible commands to use to open a url.
func Commands() [][]string {
var cmds [][]string
if exe := os.Getenv("BROWSER"); exe != "" {
cmds = append(cmds, []string{exe})
}
switch runtime.GOOS {
case "darwin":
cmds = append(cmds, []string{"/usr/bin/open"})
case "windows":
cmds = append(cmds, []string{"cmd", "/c", "start"})
default:
cmds = append(cmds, []string{"xdg-open"})
}
cmds = append(cmds,
[]string{"chrome"},
[]string{"google-chrome"},
[]string{"chromium"},
[]string{"firefox"},
)
return cmds
}
// Open tries to open url in a browser and reports whether it succeeded.
func Open(url string) bool {
for _, args := range Commands() {
cmd := exec.Command(args[0], append(args[1:], url)...)
if cmd.Start() == nil {
return true
}
}
return false
}