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