github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/geth/bugcmd.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 //版权所有2017 Go Ethereum作者 10 //此文件是Go以太坊的一部分。 11 // 12 //Go以太坊是免费软件:您可以重新发布和/或修改它 13 //根据GNU通用公共许可证的条款 14 //自由软件基金会,或者许可证的第3版,或者 15 //(由您选择)任何更高版本。 16 // 17 //Go以太坊的分布希望它会有用, 18 //但没有任何保证;甚至没有 19 //适销性或特定用途的适用性。见 20 //GNU通用公共许可证了解更多详细信息。 21 // 22 //你应该已经收到一份GNU通用公共许可证的副本 23 //一起去以太坊吧。如果没有,请参见<http://www.gnu.org/licenses/>。 24 25 package main 26 27 import ( 28 "bytes" 29 "fmt" 30 "io" 31 "io/ioutil" 32 "net/url" 33 "os/exec" 34 "runtime" 35 "strings" 36 37 "github.com/ethereum/go-ethereum/cmd/internal/browser" 38 "github.com/ethereum/go-ethereum/params" 39 40 "github.com/ethereum/go-ethereum/cmd/utils" 41 cli "gopkg.in/urfave/cli.v1" 42 ) 43 44 var bugCommand = cli.Command{ 45 Action: utils.MigrateFlags(reportBug), 46 Name: "bug", 47 Usage: "opens a window to report a bug on the geth repo", 48 ArgsUsage: " ", 49 Category: "MISCELLANEOUS COMMANDS", 50 } 51 52 const issueURL = "https:// 53 54 // 55 //跟踪并将默认值设置为问题主体。 56 func reportBug(ctx *cli.Context) error { 57 //执行模板并将内容写入buff 58 var buff bytes.Buffer 59 60 fmt.Fprintln(&buff, "#### System information") 61 fmt.Fprintln(&buff) 62 fmt.Fprintln(&buff, "Version:", params.VersionWithMeta) 63 fmt.Fprintln(&buff, "Go Version:", runtime.Version()) 64 fmt.Fprintln(&buff, "OS:", runtime.GOOS) 65 printOSDetails(&buff) 66 fmt.Fprintln(&buff, header) 67 68 //打开新的GH问题 69 if !browser.Open(issueURL + "?body=" + url.QueryEscape(buff.String())) { 70 fmt.Printf("Please file a new issue at %s using this template:\n\n%s", issueURL, buff.String()) 71 } 72 return nil 73 } 74 75 // 76 func printOSDetails(w io.Writer) { 77 switch runtime.GOOS { 78 case "darwin": 79 printCmdOut(w, "uname -v: ", "uname", "-v") 80 printCmdOut(w, "", "sw_vers") 81 case "linux": 82 printCmdOut(w, "uname -sr: ", "uname", "-sr") 83 printCmdOut(w, "", "lsb_release", "-a") 84 case "openbsd", "netbsd", "freebsd", "dragonfly": 85 printCmdOut(w, "uname -v: ", "uname", "-v") 86 case "solaris": 87 out, err := ioutil.ReadFile("/etc/release") 88 if err == nil { 89 fmt.Fprintf(w, "/etc/release: %s\n", out) 90 } else { 91 fmt.Printf("failed to read /etc/release: %v\n", err) 92 } 93 } 94 } 95 96 //printcmdout打印运行给定命令的输出。 97 // 98 // 99 // 100 func printCmdOut(w io.Writer, prefix, path string, args ...string) { 101 cmd := exec.Command(path, args...) 102 out, err := cmd.Output() 103 if err != nil { 104 fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err) 105 return 106 } 107 fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out)) 108 } 109 110 const header = ` 111 #### Expected behaviour 112 113 114 #### Actual behaviour 115 116 117 #### Steps to reproduce the behaviour 118 119 120 #### Backtrace 121 `