( prompts: PromptGroup<T>, opts?: PromptGroupOptions<T> )
| 58 | * ``` |
| 59 | */ |
| 60 | export const group = async <T>( |
| 61 | prompts: PromptGroup<T>, |
| 62 | opts?: PromptGroupOptions<T> |
| 63 | ): Promise<Prettify<PromptGroupAwaitedReturn<T>>> => { |
| 64 | const results = {} as any; |
| 65 | const promptNames = Object.keys(prompts); |
| 66 | |
| 67 | for (const name of promptNames) { |
| 68 | const prompt = prompts[name as keyof T]; |
| 69 | const result = await prompt({ results })?.catch((e) => { |
| 70 | throw e; |
| 71 | }); |
| 72 | |
| 73 | // Pass the results to the onCancel function |
| 74 | // so the user can decide what to do with the results |
| 75 | // TODO: Switch to callback within core to avoid isCancel Fn |
| 76 | if (typeof opts?.onCancel === 'function' && isCancel(result)) { |
| 77 | results[name] = 'canceled'; |
| 78 | opts.onCancel({ results }); |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | results[name] = result; |
| 83 | } |
| 84 | |
| 85 | return results; |
| 86 | }; |
nothing calls this directly
no test coverage detected