github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/cmd/intchain/bugcmd.go (about) 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 17 package main 18 19 import ( 20 "bytes" 21 "fmt" 22 "io" 23 "io/ioutil" 24 "os/exec" 25 "runtime" 26 "strings" 27 28 //"github.com/intfoundation/intchain/cmd/internal/browser" 29 "github.com/intfoundation/intchain/params" 30 31 "github.com/intfoundation/intchain/cmd/utils" 32 "gopkg.in/urfave/cli.v1" 33 ) 34 35 var bugCommand = cli.Command{ 36 Action: utils.MigrateFlags(reportBug), 37 Name: "bug", 38 Usage: "opens a window to report a bug on the intchain repo", 39 ArgsUsage: " ", 40 Category: "MISCELLANEOUS COMMANDS", 41 } 42 43 const issueUrl = "https://github.com/intfoundation/intchain/issues/new" 44 45 // reportBug reports a bug by opening a new URL to the go-ethereum GH issue 46 // tracker and setting default values as the issue body. 47 func reportBug(ctx *cli.Context) error { 48 // execute template and write contents to buff 49 var buff bytes.Buffer 50 51 fmt.Fprintln(&buff, header) 52 fmt.Fprintln(&buff, "Version:", params.Version) 53 fmt.Fprintln(&buff, "Go Version:", runtime.Version()) 54 fmt.Fprintln(&buff, "OS:", runtime.GOOS) 55 printOSDetails(&buff) 56 57 // open a new GH issue 58 //if !browser.Open(issueUrl + "?body=" + url.QueryEscape(buff.String())) { 59 // fmt.Printf("Please file a new issue at %s using this template:\n%s", issueUrl, buff.String()) 60 //} 61 return nil 62 } 63 64 // copied from the Go source. Copyright 2017 The Go Authors 65 func printOSDetails(w io.Writer) { 66 switch runtime.GOOS { 67 case "darwin": 68 printCmdOut(w, "uname -v: ", "uname", "-v") 69 printCmdOut(w, "", "sw_vers") 70 case "linux": 71 printCmdOut(w, "uname -sr: ", "uname", "-sr") 72 printCmdOut(w, "", "lsb_release", "-a") 73 case "openbsd", "netbsd", "freebsd", "dragonfly": 74 printCmdOut(w, "uname -v: ", "uname", "-v") 75 case "solaris": 76 out, err := ioutil.ReadFile("/etc/release") 77 if err == nil { 78 fmt.Fprintf(w, "/etc/release: %s\n", out) 79 } else { 80 fmt.Printf("failed to read /etc/release: %v\n", err) 81 } 82 } 83 } 84 85 // printCmdOut prints the output of running the given command. 86 // It ignores failures; 'go bug' is best effort. 87 // 88 // copied from the Go source. Copyright 2017 The Go Authors 89 func printCmdOut(w io.Writer, prefix, path string, args ...string) { 90 cmd := exec.Command(path, args...) 91 out, err := cmd.Output() 92 if err != nil { 93 fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err) 94 return 95 } 96 fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out)) 97 } 98 99 const header = `Please answer these questions before submitting your issue. Thanks! 100 101 #### What did you do? 102 103 #### What did you expect to see? 104 105 #### What did you see instead? 106 107 #### System details 108 `