MCPcopy Create free account
hub / github.com/chhoumann/quickadd / createPlugin

Function createPlugin

src/cli/registerQuickAddCliHandlers.test.ts:56–95  ·  view source on GitHub ↗
(choices: IChoice[])

Source from the content-addressed store, hash-verified

54}
55
56function createPlugin(choices: IChoice[]) {
57 const handlers: RegisteredCliHandler[] = [];
58 const { byName, byId } = flattenChoices(choices);
59
60 const plugin = {
61 app: {},
62 settings: {
63 choices,
64 },
65 getChoiceByName: vi.fn((name: string) => {
66 const choice = byName.get(name);
67 if (!choice) throw new Error(`Choice ${name} not found`);
68 return choice;
69 }),
70 getChoiceById: vi.fn((id: string) => {
71 const choice = byId.get(id);
72 if (!choice) throw new Error(`Choice ${id} not found`);
73 return choice;
74 }),
75 registerCliHandler: vi.fn(
76 (
77 command: string,
78 description: string,
79 flags: CliFlags | null,
80 handler: (params: CliData) => string | Promise<string>,
81 ) => {
82 handlers.push({ command, description, flags, handler });
83 },
84 ),
85 } as unknown as QuickAdd & {
86 registerCliHandler: (
87 command: string,
88 description: string,
89 flags: CliFlags | null,
90 handler: (params: CliData) => string | Promise<string>,
91 ) => void;
92 };
93
94 return { plugin, handlers };
95}
96
97describe("registerQuickAddCliHandlers", () => {
98 let executors: IChoiceExecutor[];

Calls 4

fnMethod · 0.80
pushMethod · 0.80
flattenChoicesFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected