(options: {
message: string;
defaultValue?: string;
})
| 23 | * undefined immediately so the caller can fail fast. |
| 24 | */ |
| 25 | export async function promptText(options: { |
| 26 | message: string; |
| 27 | defaultValue?: string; |
| 28 | }): Promise<string | undefined> { |
| 29 | if (!isInteractive()) return undefined; |
| 30 | |
| 31 | const { defaultValue, message } = options; |
| 32 | const inquirer = await import('@clack/prompts'); |
| 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 34 | const val = await (inquirer as any).text({ |
| 35 | message, |
| 36 | default: defaultValue, |
| 37 | placeholder: defaultValue, |
| 38 | }); |
| 39 | |
| 40 | // @clack/prompts returns a Symbol.cancel when the user presses Ctrl+C |
| 41 | if (typeof val === 'symbol') return undefined; |
| 42 | return val as string; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Like promptText but confirms with y/N before proceeding. |
no test coverage detected