1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:28:33 -06:00

internal/lsp, internal/tool: clean up command line of gopls

Descriptions of certain commands were changed to not start with capital
letter.

All of the commands were splitted into so called main
commands and feature commands.

Package tool did have a limitation that revealed itself when command
was invoked only with `-h`, i.e. `gopls -h`. Limitation was that in
above mentioned case, FlagSet.Parse() was intercepting `-h` flag and
printing just default usage.

Updates golang/go#35855

Change-Id: I9bd27fc72e8fb8d18025d95ebcae974dd5583e91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210359
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Jędrzej Szczepaniak 2019-12-07 14:10:13 +01:00 committed by Ian Cottrell
parent 49a3e744a4
commit a0e659d513
3 changed files with 36 additions and 6 deletions

View File

@ -61,10 +61,10 @@ type Application struct {
Remote string `flag:"remote" help:"*EXPERIMENTAL* - forward all commands to a remote lsp"`
// Enable verbose logging
Verbose bool `flag:"v" help:"Verbose output"`
Verbose bool `flag:"v" help:"verbose output"`
// Control ocagent export of telemetry
OCAgent string `flag:"ocagent" help:"The address of the ocagent, or off"`
OCAgent string `flag:"ocagent" help:"the address of the ocagent, or off"`
// PrepareOptions is called to update the options when a new view is built.
// It is primarily to allow the behavior of gopls to be modified by hooks.
@ -101,9 +101,22 @@ func (app *Application) ShortHelp() string {
// This includes the short help for all the sub commands.
func (app *Application) DetailedHelp(f *flag.FlagSet) {
fmt.Fprint(f.Output(), `
gopls is a Go language server. It is typically used with an editor to provide
language features. When no command is specified, gopls will default to the 'serve'
command. The language features can also be accessed via the gopls command-line interface.
Available commands are:
`, app.Name(), app.Name(), app.Serve.Name())
fmt.Fprint(f.Output(), `
main:
`)
for _, c := range app.commands() {
for _, c := range app.mainCommands() {
fmt.Fprintf(f.Output(), " %s : %v\n", c.Name(), c.ShortHelp())
}
fmt.Fprint(f.Output(), `
features:
`)
for _, c := range app.featureCommands() {
fmt.Fprintf(f.Output(), " %s : %v\n", c.Name(), c.ShortHelp())
}
fmt.Fprint(f.Output(), `
@ -138,9 +151,22 @@ func (app *Application) Run(ctx context.Context, args ...string) error {
// command line.
// The command is specified by the first non flag argument.
func (app *Application) commands() []tool.Application {
var commands []tool.Application
commands = append(commands, app.mainCommands()...)
commands = append(commands, app.featureCommands()...)
return commands
}
func (app *Application) mainCommands() []tool.Application {
return []tool.Application{
&app.Serve,
&version{app: app},
&bug{},
}
}
func (app *Application) featureCommands() []tool.Application {
return []tool.Application{
&check{app: app},
&foldingRanges{app: app},
&format{app: app},
@ -154,7 +180,6 @@ func (app *Application) commands() []tool.Application {
&signature{app: app},
&suggestedfix{app: app},
&symbols{app: app},
&version{app: app},
}
}

View File

@ -34,8 +34,8 @@ type Serve struct {
Mode string `flag:"mode" help:"no effect"`
Port int `flag:"port" help:"port on which to run gopls for debugging purposes"`
Address string `flag:"listen" help:"address on which to listen for remote connections"`
Trace bool `flag:"rpc.trace" help:"Print the full rpc trace in lsp inspector format"`
Debug string `flag:"debug" help:"Serve debug information on the supplied address"`
Trace bool `flag:"rpc.trace" help:"print the full rpc trace in lsp inspector format"`
Debug string `flag:"debug" help:"serve debug information on the supplied address"`
app *Application
}

View File

@ -102,6 +102,11 @@ func Main(ctx context.Context, app Application, args []string) {
// error.
func Run(ctx context.Context, app Application, args []string) error {
s := flag.NewFlagSet(app.Name(), flag.ExitOnError)
s.Usage = func() {
fmt.Fprint(s.Output(), app.ShortHelp())
fmt.Fprintf(s.Output(), "\n\nUsage: %v [flags] %v\n", app.Name(), app.Usage())
app.DetailedHelp(s)
}
p := addFlags(s, reflect.StructField{}, reflect.ValueOf(app))
s.Parse(args)