bugcmd.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "bytes"
  19. "fmt"
  20. "io"
  21. "io/ioutil"
  22. "net/url"
  23. "os/exec"
  24. "runtime"
  25. "strings"
  26. "github.com/ethereum/go-ethereum/cmd/internal/browser"
  27. "github.com/ethereum/go-ethereum/params"
  28. "github.com/ethereum/go-ethereum/cmd/utils"
  29. cli "gopkg.in/urfave/cli.v1"
  30. )
  31. var bugCommand = cli.Command{
  32. Action: utils.MigrateFlags(reportBug),
  33. Name: "bug",
  34. Usage: "opens a window to report a bug on the geth repo",
  35. ArgsUsage: " ",
  36. Category: "MISCELLANEOUS COMMANDS",
  37. }
  38. const issueURL = "https://github.com/ethereum/go-ethereum/issues/new"
  39. // reportBug reports a bug by opening a new URL to the go-ethereum GH issue
  40. // tracker and setting default values as the issue body.
  41. func reportBug(ctx *cli.Context) error {
  42. // execute template and write contents to buff
  43. var buff bytes.Buffer
  44. fmt.Fprintln(&buff, "#### System information")
  45. fmt.Fprintln(&buff)
  46. fmt.Fprintln(&buff, "Version:", params.Version)
  47. fmt.Fprintln(&buff, "Go Version:", runtime.Version())
  48. fmt.Fprintln(&buff, "OS:", runtime.GOOS)
  49. printOSDetails(&buff)
  50. fmt.Fprintln(&buff, header)
  51. // open a new GH issue
  52. if !browser.Open(issueURL + "?body=" + url.QueryEscape(buff.String())) {
  53. fmt.Printf("Please file a new issue at %s using this template:\n\n%s", issueURL, buff.String())
  54. }
  55. return nil
  56. }
  57. // copied from the Go source. Copyright 2017 The Go Authors
  58. func printOSDetails(w io.Writer) {
  59. switch runtime.GOOS {
  60. case "darwin":
  61. printCmdOut(w, "uname -v: ", "uname", "-v")
  62. printCmdOut(w, "", "sw_vers")
  63. case "linux":
  64. printCmdOut(w, "uname -sr: ", "uname", "-sr")
  65. printCmdOut(w, "", "lsb_release", "-a")
  66. case "openbsd", "netbsd", "freebsd", "dragonfly":
  67. printCmdOut(w, "uname -v: ", "uname", "-v")
  68. case "solaris":
  69. out, err := ioutil.ReadFile("/etc/release")
  70. if err == nil {
  71. fmt.Fprintf(w, "/etc/release: %s\n", out)
  72. } else {
  73. fmt.Printf("failed to read /etc/release: %v\n", err)
  74. }
  75. }
  76. }
  77. // printCmdOut prints the output of running the given command.
  78. // It ignores failures; 'go bug' is best effort.
  79. //
  80. // copied from the Go source. Copyright 2017 The Go Authors
  81. func printCmdOut(w io.Writer, prefix, path string, args ...string) {
  82. cmd := exec.Command(path, args...)
  83. out, err := cmd.Output()
  84. if err != nil {
  85. fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err)
  86. return
  87. }
  88. fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
  89. }
  90. const header = `
  91. #### Expected behaviour
  92. #### Actual behaviour
  93. #### Steps to reproduce the behaviour
  94. #### Backtrace
  95. `