Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function promptMenu(menu: IMenu, pageSize: number, defaults: string[], choice: string[]): Promise & { close: () => void } {
const choices = createChoices(menu);
let close = false;
defaults = [...defaults];
if (choices.length === 0) {
console.log('Nothing to do: Menu not available and no action specified.');
throw new Error('Nothing to do: Menu not available and no action specified.');
}
let initialIndex = choices.findIndex((item) => item.title === defaults[0]);
if (initialIndex === -1) initialIndex = 0;
const selectMenu = new SelectPrompt(
{
type: 'select',
name: 'value',
message: 'Select' + (menu.description ? ' ' + menu.description : ''),
initial: initialIndex,
choices: choices,
},
);
const menuPromise = toPromise(selectMenu);
const resultPromise = menuPromise.then((answer) => {
if (close || answer.length === 0) return null;
const menuItem = findMenuItem(menu, answer[0]);
if (menuItem === null) {