MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / withHostAndSignalHandlers

Function withHostAndSignalHandlers

apps/cli/src/commands/cli/list.ts:233–258  ·  view source on GitHub ↗
(
	options: BaseListOptions,
	hostOptions: ListHostOptions,
	fn: (host: ExtensionHost) => Promise<T>,
)

Source from the content-addressed store, hash-verified

231}
232
233async function withHostAndSignalHandlers<T>(
234 options: BaseListOptions,
235 hostOptions: ListHostOptions,
236 fn: (host: ExtensionHost) => Promise<T>,
237): Promise<T> {
238 const host = await createListHost(options, hostOptions)
239
240 const shutdown = async (exitCode: number) => {
241 await host.dispose()
242 process.exit(exitCode)
243 }
244
245 const onSigint = () => void shutdown(130)
246 const onSigterm = () => void shutdown(143)
247
248 process.on("SIGINT", onSigint)
249 process.on("SIGTERM", onSigterm)
250
251 try {
252 return await fn(host)
253 } finally {
254 process.off("SIGINT", onSigint)
255 process.off("SIGTERM", onSigterm)
256 await host.dispose()
257 }
258}
259
260export async function listCommands(options: BaseListOptions): Promise<void> {
261 const format = parseFormat(options.format)

Callers 3

listCommandsFunction · 0.85
listModesFunction · 0.85
listModelsFunction · 0.85

Calls 4

createListHostFunction · 0.85
onMethod · 0.65
offMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected