creates a new startCmd params: commandName: what to call the base command in examples (e.g., "docker-language-server")
(baseCommandName string)
| 33 | // |
| 34 | // commandName: what to call the base command in examples (e.g., "docker-language-server") |
| 35 | func newStartCmd(baseCommandName string) *startCmd { |
| 36 | cmd := startCmd{ |
| 37 | Command: &cobra.Command{ |
| 38 | Use: "start", |
| 39 | Short: "Start the Docker LSP server", |
| 40 | Long: `Start the Docker LSP server. |
| 41 | |
| 42 | By default, the server will run in stdio mode: requests should be written to |
| 43 | stdin and responses will be written to stdout. (All logging is _always_ done |
| 44 | to stderr.) |
| 45 | |
| 46 | For socket mode, pass the --address option. |
| 47 | `, |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | var example bytes.Buffer |
| 52 | p := exampleTemplateParams{ |
| 53 | BaseCommandName: baseCommandName, |
| 54 | } |
| 55 | err := exampleTemplate.Execute(&example, p) |
| 56 | if err != nil { |
| 57 | panic(err) |
| 58 | } |
| 59 | cmd.Example = example.String() |
| 60 | |
| 61 | cmd.RunE = func(cc *cobra.Command, args []string) error { |
| 62 | ctx := cc.Context() |
| 63 | if cmd.address != "" { |
| 64 | err = runSocketServer(ctx, cmd.address) |
| 65 | } else { |
| 66 | err = runStdioServer(ctx) |
| 67 | } |
| 68 | if err == context.Canceled { |
| 69 | err = nil |
| 70 | } |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | cmd.Flags().StringVar(&cmd.address, "address", "", |
| 75 | "Address (hostname:port) to listen on") |
| 76 | cmd.Flags().BoolVar(&cmd.stdio, "stdio", false, |
| 77 | "Stdio (use stdin and stdout to communicate)") |
| 78 | cmd.MarkFlagsMutuallyExclusive("address", "stdio") |
| 79 | cmd.MarkFlagsOneRequired("address", "stdio") |
| 80 | |
| 81 | return &cmd |
| 82 | } |
| 83 | |
| 84 | func runStdioServer(_ context.Context) error { |
| 85 | docManager := document.NewDocumentManager() |
no test coverage detected