github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/geth/bugcmd.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package main 13 14 import ( 15 "bytes" 16 "fmt" 17 "io" 18 "io/ioutil" 19 "net/url" 20 "os/exec" 21 "runtime" 22 "strings" 23 24 "github.com/Sberex/go-sberex/cmd/internal/browser" 25 "github.com/Sberex/go-sberex/params" 26 27 "github.com/Sberex/go-sberex/cmd/utils" 28 cli "gopkg.in/urfave/cli.v1" 29 ) 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 39 const issueUrl = "https://github.com/Sberex/go-sberex/issues/new" 40 41 // reportBug reports a bug by opening a new URL to the go-sberex GH issue 42 // tracker and setting default values as the issue body. 43 func reportBug(ctx *cli.Context) error { 44 // execute template and write contents to buff 45 var buff bytes.Buffer 46 47 fmt.Fprintln(&buff, header) 48 fmt.Fprintln(&buff, "Version:", params.Version) 49 fmt.Fprintln(&buff, "Go Version:", runtime.Version()) 50 fmt.Fprintln(&buff, "OS:", runtime.GOOS) 51 printOSDetails(&buff) 52 53 // open a new GH issue 54 if !browser.Open(issueUrl + "?body=" + url.QueryEscape(buff.String())) { 55 fmt.Printf("Please file a new issue at %s using this template:\n%s", issueUrl, buff.String()) 56 } 57 return nil 58 } 59 60 // copied from the Go source. Copyright 2017 The Go Authors 61 func printOSDetails(w io.Writer) { 62 switch runtime.GOOS { 63 case "darwin": 64 printCmdOut(w, "uname -v: ", "uname", "-v") 65 printCmdOut(w, "", "sw_vers") 66 case "linux": 67 printCmdOut(w, "uname -sr: ", "uname", "-sr") 68 printCmdOut(w, "", "lsb_release", "-a") 69 case "openbsd", "netbsd", "freebsd", "dragonfly": 70 printCmdOut(w, "uname -v: ", "uname", "-v") 71 case "solaris": 72 out, err := ioutil.ReadFile("/etc/release") 73 if err == nil { 74 fmt.Fprintf(w, "/etc/release: %s\n", out) 75 } else { 76 fmt.Printf("failed to read /etc/release: %v\n", err) 77 } 78 } 79 } 80 81 // printCmdOut prints the output of running the given command. 82 // It ignores failures; 'go bug' is best effort. 83 // 84 // copied from the Go source. Copyright 2017 The Go Authors 85 func printCmdOut(w io.Writer, prefix, path string, args ...string) { 86 cmd := exec.Command(path, args...) 87 out, err := cmd.Output() 88 if err != nil { 89 fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err) 90 return 91 } 92 fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out)) 93 } 94 95 const header = `Please answer these questions before submitting your issue. Thanks! 96 97 #### What did you do? 98 99 #### What did you expect to see? 100 101 #### What did you see instead? 102 103 #### System details 104 `