github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/cmd/geth/bugcmd.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:28</date> 10 //</624342590791094272> 11 12 13 package main 14 15 import ( 16 "bytes" 17 "fmt" 18 "io" 19 "io/ioutil" 20 "net/url" 21 "os/exec" 22 "runtime" 23 "strings" 24 25 "github.com/ethereum/go-ethereum/cmd/internal/browser" 26 "github.com/ethereum/go-ethereum/params" 27 28 "github.com/ethereum/go-ethereum/cmd/utils" 29 cli "gopkg.in/urfave/cli.v1" 30 ) 31 32 var bugCommand = cli.Command{ 33 Action: utils.MigrateFlags(reportBug), 34 Name: "bug", 35 Usage: "opens a window to report a bug on the geth repo", 36 ArgsUsage: " ", 37 Category: "MISCELLANEOUS COMMANDS", 38 } 39 40 const issueURL = "https:// 41 42 // 43 //跟踪并将默认值设置为问题主体。 44 func reportBug(ctx *cli.Context) error { 45 //执行模板并将内容写入buff 46 var buff bytes.Buffer 47 48 fmt.Fprintln(&buff, "#### System information") 49 fmt.Fprintln(&buff) 50 fmt.Fprintln(&buff, "Version:", params.VersionWithMeta) 51 fmt.Fprintln(&buff, "Go Version:", runtime.Version()) 52 fmt.Fprintln(&buff, "OS:", runtime.GOOS) 53 printOSDetails(&buff) 54 fmt.Fprintln(&buff, header) 55 56 //打开新的GH问题 57 if !browser.Open(issueURL + "?body=" + url.QueryEscape(buff.String())) { 58 fmt.Printf("Please file a new issue at %s using this template:\n\n%s", issueURL, buff.String()) 59 } 60 return nil 61 } 62 63 // 64 func printOSDetails(w io.Writer) { 65 switch runtime.GOOS { 66 case "darwin": 67 printCmdOut(w, "uname -v: ", "uname", "-v") 68 printCmdOut(w, "", "sw_vers") 69 case "linux": 70 printCmdOut(w, "uname -sr: ", "uname", "-sr") 71 printCmdOut(w, "", "lsb_release", "-a") 72 case "openbsd", "netbsd", "freebsd", "dragonfly": 73 printCmdOut(w, "uname -v: ", "uname", "-v") 74 case "solaris": 75 out, err := ioutil.ReadFile("/etc/release") 76 if err == nil { 77 fmt.Fprintf(w, "/etc/release: %s\n", out) 78 } else { 79 fmt.Printf("failed to read /etc/release: %v\n", err) 80 } 81 } 82 } 83 84 //printcmdout打印运行给定命令的输出。 85 // 86 // 87 // 88 func printCmdOut(w io.Writer, prefix, path string, args ...string) { 89 cmd := exec.Command(path, args...) 90 out, err := cmd.Output() 91 if err != nil { 92 fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err) 93 return 94 } 95 fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out)) 96 } 97 98 const header = ` 99 #### Expected behaviour 100 101 102 #### Actual behaviour 103 104 105 #### Steps to reproduce the behaviour 106 107 108 #### Backtrace 109 ` 110