MCPcopy Create free account
hub / github.com/docker/docker-language-server / newStartCmd

Function newStartCmd

internal/pkg/cli/start.go:35–82  ·  view source on GitHub ↗

creates a new startCmd params: commandName: what to call the base command in examples (e.g., "docker-language-server")

(baseCommandName string)

Source from the content-addressed store, hash-verified

33//
34// commandName: what to call the base command in examples (e.g., "docker-language-server")
35func 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
42By default, the server will run in stdio mode: requests should be written to
43stdin and responses will be written to stdout. (All logging is _always_ done
44to stderr.)
45
46For 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
84func runStdioServer(_ context.Context) error {
85 docManager := document.NewDocumentManager()

Callers 1

NewRootCmdFunction · 0.85

Calls 3

runSocketServerFunction · 0.85
runStdioServerFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected