MCPcopy
hub / github.com/coder/mux / createCliRunner

Function createCliRunner

src/cli/cli.test.ts:86–109  ·  view source on GitHub ↗

* Create a CLI runner that executes commands against a running server. * Uses trpc-cli's programmatic API to avoid subprocess overhead.

(baseUrl: string, authToken?: string)

Source from the content-addressed store, hash-verified

84 * Uses trpc-cli's programmatic API to avoid subprocess overhead.
85 */
86function createCliRunner(baseUrl: string, authToken?: string) {
87 const proxiedRouter = proxifyOrpc(router(), { baseUrl, authToken });
88 const cli = createCli({ router: proxiedRouter });
89
90 return async (args: string[]): Promise<unknown> => {
91 return cli
92 .run({
93 argv: args,
94 process: { exit: () => void 0 as never },
95 // eslint-disable-next-line @typescript-eslint/no-empty-function
96 logger: { info: () => {}, error: () => {} },
97 })
98 .catch((err) => {
99 // Extract the result or re-throw the actual error
100 while (err instanceof FailedToExitError) {
101 if (err.exitCode === 0) {
102 return err.cause; // This is the return value of the procedure
103 }
104 err = err.cause; // Use the underlying error
105 }
106 throw err;
107 });
108 };
109}
110
111// --- Tests ---
112

Callers 1

cli.test.tsFile · 0.85

Calls 3

proxifyOrpcFunction · 0.90
routerFunction · 0.90
runMethod · 0.65

Tested by

no test coverage detected