(opts: {
value: string | undefined;
message: string;
cancelMessage: string;
flagName: string;
usageHint: string;
nonInteractive?: boolean;
})
| 74 | } |
| 75 | |
| 76 | export async function promptOrFail(opts: { |
| 77 | value: string | undefined; |
| 78 | message: string; |
| 79 | cancelMessage: string; |
| 80 | flagName: string; |
| 81 | usageHint: string; |
| 82 | nonInteractive?: boolean; |
| 83 | }): Promise<string> { |
| 84 | if (opts.value) return opts.value; |
| 85 | |
| 86 | if (isInteractive({ nonInteractive: opts.nonInteractive })) { |
| 87 | const hint = await promptText({ message: opts.message }); |
| 88 | if (!hint) { |
| 89 | process.stderr.write(opts.cancelMessage + '\n'); |
| 90 | process.exit(1); |
| 91 | } |
| 92 | return hint; |
| 93 | } |
| 94 | |
| 95 | failIfMissing(opts.flagName, opts.usageHint); |
| 96 | } |
no test coverage detected