| 5 | import { select, input, confirm, checkbox, password } from "@inquirer/prompts"; |
| 6 | |
| 7 | export class Prompter { |
| 8 | /** |
| 9 | * @param {{ message: string, choices: { name: string, value: string }[]}} options |
| 10 | */ |
| 11 | select(options) { |
| 12 | return select(options); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * @param {{ message: string }} options |
| 17 | */ |
| 18 | input(options) { |
| 19 | return input(options); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param {{ message: string }} options |
| 24 | */ |
| 25 | password(options) { |
| 26 | return password({ ...options, mask: true }); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @param {string} prompt |
| 31 | */ |
| 32 | checkContinue = async (prompt = "") => { |
| 33 | const prefix = prompt && `${prompt} `; |
| 34 | const ok = await this.confirm({ |
| 35 | message: `${prefix}Continue?`, |
| 36 | }); |
| 37 | if (!ok) throw new Error("Exiting..."); |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * @param {{ message: string }} options |
| 42 | */ |
| 43 | confirm(options) { |
| 44 | return confirm(options); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param {{ message: string, choices: { name: string, value: string }[]}} options |
| 49 | */ |
| 50 | checkbox(options) { |
| 51 | return checkbox(options); |
| 52 | } |
| 53 | } |
| 54 | // snippet-end:[javascript.v3.utils.prompter] |