github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/neatio/bugcmd.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"io"
     7  	"io/ioutil"
     8  	"os/exec"
     9  	"runtime"
    10  	"strings"
    11  
    12  	"github.com/neatlab/neatio/params"
    13  
    14  	"github.com/neatlab/neatio/utilities/utils"
    15  	"gopkg.in/urfave/cli.v1"
    16  )
    17  
    18  var bugCommand = cli.Command{
    19  	Action:    utils.MigrateFlags(reportBug),
    20  	Name:      "bug",
    21  	Usage:     "opens a window to report a bug on the neatio repo",
    22  	ArgsUsage: " ",
    23  	Category:  "MISCELLANEOUS COMMANDS",
    24  }
    25  
    26  const issueUrl = "https://github.com/neatlab/neatio/issues/new"
    27  
    28  func reportBug(ctx *cli.Context) error {
    29  	var buff bytes.Buffer
    30  
    31  	fmt.Fprintln(&buff, header)
    32  	fmt.Fprintln(&buff, "Version:", params.Version)
    33  	fmt.Fprintln(&buff, "Go Version:", runtime.Version())
    34  	fmt.Fprintln(&buff, "OS:", runtime.GOOS)
    35  	printOSDetails(&buff)
    36  
    37  	return nil
    38  }
    39  
    40  func printOSDetails(w io.Writer) {
    41  	switch runtime.GOOS {
    42  	case "darwin":
    43  		printCmdOut(w, "uname -v: ", "uname", "-v")
    44  		printCmdOut(w, "", "sw_vers")
    45  	case "linux":
    46  		printCmdOut(w, "uname -sr: ", "uname", "-sr")
    47  		printCmdOut(w, "", "lsb_release", "-a")
    48  	case "openbsd", "netbsd", "freebsd", "dragonfly":
    49  		printCmdOut(w, "uname -v: ", "uname", "-v")
    50  	case "solaris":
    51  		out, err := ioutil.ReadFile("/etc/release")
    52  		if err == nil {
    53  			fmt.Fprintf(w, "/etc/release: %s\n", out)
    54  		} else {
    55  			fmt.Printf("failed to read /etc/release: %v\n", err)
    56  		}
    57  	}
    58  }
    59  
    60  func printCmdOut(w io.Writer, prefix, path string, args ...string) {
    61  	cmd := exec.Command(path, args...)
    62  	out, err := cmd.Output()
    63  	if err != nil {
    64  		fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err)
    65  		return
    66  	}
    67  	fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
    68  }
    69  
    70  const header = `Please answer these questions before submitting your issue. Thanks!
    71  
    72  #### What did you do?
    73   
    74  #### What did you expect to see?
    75   
    76  #### What did you saw instead?
    77   
    78  #### System details (OS)
    79  `