UNPKG

easy-cli-framework

Version:

A framework for building CLI applications that are robust and easy to maintain. Supports theming, configuration files, interactive prompts, and more.

48 lines (44 loc) 1.5 kB
'use strict'; var yargsInteractive = require('yargs-interactive'); // @ts-ignore Untyped Module /** * Prompts the user to confirm a prompt. * * @param {string} prompt The prompt to display to the user * @param {PromptConfirmOptions} options The options for the prompt * * @returns {Promise<boolean>} The choice the user selected * * @example * ```typescript * // Prompt the user to confirm a prompt * const choice = await promptConfirm('Are you sure?'); * console.log(choice); * * // Prompt the user to confirm a prompt with a default option * const choice = await promptConfirm('Are you sure?', { defaultOption: true }); * console.log(choice); * * // Prompt the user to confirm a prompt using a custom theme * const choice = await promptConfirm('Are you sure?', { * theme: new EasyCLITheme(), * promptTheme: 'info', * }); * ``` */ const promptConfirm = async (prompt, { defaultOption = false, theme = null, promptTheme = 'default', } = {}) => { var _a; return yargsInteractive() .usage('$0 <command> [args]') .interactive({ interactive: { default: true }, confirm: { type: 'confirm', describe: (_a = theme === null || theme === undefined ? undefined : theme.formattedString(prompt, promptTheme)) !== null && _a !== undefined ? _a : prompt, prompt: 'always', default: defaultOption, }, }) .then(({ confirm }) => confirm); }; exports.promptConfirm = promptConfirm;