diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index 13020d4df3..6007b1f1ef 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -105,11 +105,11 @@ func New(name, wd string, env []string, options func(*source.Options)) *Applicat func (app *Application) Name() string { return app.name } // Usage implements tool.Application returning empty extra argument usage. -func (app *Application) Usage() string { return " [command-flags] [command-args]" } +func (app *Application) Usage() string { return "" } // ShortHelp implements tool.Application returning the main binary help. func (app *Application) ShortHelp() string { - return "The Go Language source tools." + return "" } // DetailedHelp implements tool.Application returning the main binary help. @@ -119,11 +119,16 @@ func (app *Application) DetailedHelp(f *flag.FlagSet) { defer w.Flush() fmt.Fprint(w, ` -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. +gopls is a Go language server. -command: +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. + +Usage: + gopls help [] + +Command: `) fmt.Fprint(w, "\nMain\t\n") for _, c := range app.mainCommands() { diff --git a/internal/lsp/cmd/serve.go b/internal/lsp/cmd/serve.go index e47d71f112..f6e2683975 100644 --- a/internal/lsp/cmd/serve.go +++ b/internal/lsp/cmd/serve.go @@ -48,7 +48,8 @@ func (s *Serve) ShortHelp() string { return "run a server for Go code using the Language Server Protocol" } func (s *Serve) DetailedHelp(f *flag.FlagSet) { - fmt.Fprint(f.Output(), ` + fmt.Fprint(f.Output(), ` gopls [flags] [server-flags] + The server communicates using JSONRPC2 on stdin and stdout, and is intended to be run directly as a child of an editor process. diff --git a/internal/lsp/cmd/subcommands.go b/internal/lsp/cmd/subcommands.go index e4045fb007..deac5c822d 100644 --- a/internal/lsp/cmd/subcommands.go +++ b/internal/lsp/cmd/subcommands.go @@ -20,7 +20,7 @@ type subcommands []tool.Application func (s subcommands) DetailedHelp(f *flag.FlagSet) { w := tabwriter.NewWriter(f.Output(), 0, 0, 2, ' ', 0) defer w.Flush() - fmt.Fprint(w, "\nsubcommands:\n") + fmt.Fprint(w, "\nSubcommand:\n") for _, c := range s { fmt.Fprintf(w, " %s\t%s\n", c.Name(), c.ShortHelp()) } diff --git a/internal/lsp/cmd/usage/inspect.hlp b/internal/lsp/cmd/usage/inspect.hlp index 8271f50c7a..3d0a0f3c4d 100644 --- a/internal/lsp/cmd/usage/inspect.hlp +++ b/internal/lsp/cmd/usage/inspect.hlp @@ -3,6 +3,6 @@ interact with the gopls daemon (deprecated: use 'remote') Usage: gopls [flags] inspect [arg]... -subcommands: +Subcommand: sessions print information about current gopls sessions debug start the debug server diff --git a/internal/lsp/cmd/usage/remote.hlp b/internal/lsp/cmd/usage/remote.hlp index cbcfd03f84..dd6034f46a 100644 --- a/internal/lsp/cmd/usage/remote.hlp +++ b/internal/lsp/cmd/usage/remote.hlp @@ -3,6 +3,6 @@ interact with the gopls daemon Usage: gopls [flags] remote [arg]... -subcommands: +Subcommand: sessions print information about current gopls sessions debug start the debug server diff --git a/internal/lsp/cmd/usage/serve.hlp b/internal/lsp/cmd/usage/serve.hlp index 74c181de9d..370cbce83d 100644 --- a/internal/lsp/cmd/usage/serve.hlp +++ b/internal/lsp/cmd/usage/serve.hlp @@ -2,6 +2,7 @@ run a server for Go code using the Language Server Protocol Usage: gopls [flags] serve [server-flags] + gopls [flags] [server-flags] The server communicates using JSONRPC2 on stdin and stdout, and is intended to be run directly as a child of an editor process. diff --git a/internal/lsp/cmd/usage/usage.hlp b/internal/lsp/cmd/usage/usage.hlp index 5f2a70cbbb..4dce00e047 100644 --- a/internal/lsp/cmd/usage/usage.hlp +++ b/internal/lsp/cmd/usage/usage.hlp @@ -1,13 +1,14 @@ -The Go Language source tools. + +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. Usage: - gopls [flags] [command-flags] [command-args] + gopls help [] -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. - -command: +Command: Main serve run a server for Go code using the Language Server Protocol diff --git a/internal/lsp/cmd/usage/workspace.hlp b/internal/lsp/cmd/usage/workspace.hlp index 8c40125b8a..912cf29461 100644 --- a/internal/lsp/cmd/usage/workspace.hlp +++ b/internal/lsp/cmd/usage/workspace.hlp @@ -3,5 +3,5 @@ manage the gopls workspace (experimental: under development) Usage: gopls [flags] workspace [arg]... -subcommands: +Subcommand: generate generate a gopls.mod file for a workspace diff --git a/internal/tool/tool.go b/internal/tool/tool.go index f7c1e42c53..526b6b7ae5 100644 --- a/internal/tool/tool.go +++ b/internal/tool/tool.go @@ -103,16 +103,18 @@ func Main(ctx context.Context, app Application, args []string) { // error. func Run(ctx context.Context, s *flag.FlagSet, app Application, args []string) error { s.Usage = func() { - fmt.Fprintf(s.Output(), "%s\n\nUsage:\n ", app.ShortHelp()) - if sub, ok := app.(SubCommand); ok && sub.Parent() != "" { - fmt.Fprintf(s.Output(), "%s [flags] %s", sub.Parent(), app.Name()) - } else { - fmt.Fprintf(s.Output(), "%s [flags]", app.Name()) + if app.ShortHelp() != "" { + fmt.Fprintf(s.Output(), "%s\n\nUsage:\n ", app.ShortHelp()) + if sub, ok := app.(SubCommand); ok && sub.Parent() != "" { + fmt.Fprintf(s.Output(), "%s [flags] %s", sub.Parent(), app.Name()) + } else { + fmt.Fprintf(s.Output(), "%s [flags]", app.Name()) + } + if usage := app.Usage(); usage != "" { + fmt.Fprintf(s.Output(), " %s", usage) + } + fmt.Fprint(s.Output(), "\n") } - if usage := app.Usage(); usage != "" { - fmt.Fprintf(s.Output(), " %s", usage) - } - fmt.Fprint(s.Output(), "\n") app.DetailedHelp(s) } p := addFlags(s, reflect.StructField{}, reflect.ValueOf(app))