github.com/april1989/origin-go-tools@v0.0.32/internal/lsp/cmd/info.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package cmd
     6  
     7  import (
     8  	"bytes"
     9  	"context"
    10  	"flag"
    11  	"fmt"
    12  	"net/url"
    13  	"os"
    14  	"strings"
    15  
    16  	"github.com/april1989/origin-go-tools/internal/lsp/browser"
    17  	"github.com/april1989/origin-go-tools/internal/lsp/debug"
    18  )
    19  
    20  // version implements the version command.
    21  type version struct {
    22  	app *Application
    23  }
    24  
    25  func (v *version) Name() string      { return "version" }
    26  func (v *version) Usage() string     { return "" }
    27  func (v *version) ShortHelp() string { return "print the gopls version information" }
    28  func (v *version) DetailedHelp(f *flag.FlagSet) {
    29  	fmt.Fprint(f.Output(), ``)
    30  	f.PrintDefaults()
    31  }
    32  
    33  // Run prints version information to stdout.
    34  func (v *version) Run(ctx context.Context, args ...string) error {
    35  	debug.PrintVersionInfo(ctx, os.Stdout, v.app.verbose(), debug.PlainText)
    36  	return nil
    37  }
    38  
    39  // bug implements the bug command.
    40  type bug struct{}
    41  
    42  func (b *bug) Name() string      { return "bug" }
    43  func (b *bug) Usage() string     { return "" }
    44  func (b *bug) ShortHelp() string { return "report a bug in gopls" }
    45  func (b *bug) DetailedHelp(f *flag.FlagSet) {
    46  	fmt.Fprint(f.Output(), ``)
    47  	f.PrintDefaults()
    48  }
    49  
    50  const goplsBugPrefix = "x/tools/gopls: <DESCRIBE THE PROBLEM>"
    51  const goplsBugHeader = `ATTENTION: Please answer these questions BEFORE submitting your issue. Thanks!
    52  
    53  #### What did you do?
    54  If possible, provide a recipe for reproducing the error.
    55  A complete runnable program is good.
    56  A link on play.golang.org is better.
    57  A failing unit test is the best.
    58  
    59  #### What did you expect to see?
    60  
    61  
    62  #### What did you see instead?
    63  
    64  
    65  `
    66  
    67  // Run collects some basic information and then prepares an issue ready to
    68  // be reported.
    69  func (b *bug) Run(ctx context.Context, args ...string) error {
    70  	buf := &bytes.Buffer{}
    71  	fmt.Fprint(buf, goplsBugHeader)
    72  	debug.PrintVersionInfo(ctx, buf, true, debug.Markdown)
    73  	body := buf.String()
    74  	title := strings.Join(args, " ")
    75  	if !strings.HasPrefix(title, goplsBugPrefix) {
    76  		title = goplsBugPrefix + title
    77  	}
    78  	if !browser.Open("https://github.com/golang/go/issues/new?title=" + url.QueryEscape(title) + "&body=" + url.QueryEscape(body)) {
    79  		fmt.Print("Please file a new issue at golang.org/issue/new using this template:\n\n")
    80  		fmt.Print(body)
    81  	}
    82  	return nil
    83  }