(choices: IChoice[])
| 54 | } |
| 55 | |
| 56 | function 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 | |
| 97 | describe("registerQuickAddCliHandlers", () => { |
| 98 | let executors: IChoiceExecutor[]; |
no test coverage detected