MCPcopy Create free account
hub / github.com/microsoft/typescript-go / runAPI

Function runAPI

cmd/tsgo/api.go:17–61  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

15)
16
17func runAPI(args []string) int {
18 flag := flag.NewFlagSet("api", flag.ContinueOnError)
19 cwd := flag.String("cwd", core.Must(os.Getwd()), "current working directory")
20 pipePath := flag.String("pipe", "", "use named pipe or Unix domain socket for communication instead of stdio")
21 callbacks := flag.String("callbacks", "", "comma-separated list of FS callbacks to enable (readFile,fileExists,directoryExists,getAccessibleEntries,realpath)")
22 async := flag.Bool("async", false, "use JSON-RPC protocol instead of MessagePack (for async API)")
23 timing := flag.Bool("timing", false, "collect per-request server processing time, folded into the client's timing snapshot")
24 if err := flag.Parse(args); err != nil {
25 return 2
26 }
27
28 defaultLibraryPath := bundled.LibPath()
29
30 // Parse callbacks list
31 var callbacksList []string
32 if *callbacks != "" {
33 callbacksList = strings.Split(*callbacks, ",")
34 }
35
36 options := &api.StdioServerOptions{
37 Err: os.Stderr,
38 Cwd: *cwd,
39 DefaultLibraryPath: defaultLibraryPath,
40 Callbacks: callbacksList,
41 Async: *async,
42 CollectTiming: *timing,
43 }
44 if *pipePath != "" {
45 options.PipePath = *pipePath
46 } else {
47 options.In = os.Stdin
48 options.Out = os.Stdout
49 }
50
51 s := api.NewStdioServer(options)
52
53 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
54 defer stop()
55
56 if err := s.Run(ctx); err != nil {
57 fmt.Fprintln(os.Stderr, err)
58 return 1
59 }
60 return 0
61}

Callers 1

runMainFunction · 0.85

Calls 6

RunMethod · 0.95
MustFunction · 0.92
LibPathFunction · 0.92
NewStdioServerFunction · 0.92
stopFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected