@warriorjs/cli
Version:
WarriorJS command line
47 lines (38 loc) • 1.06 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SEPARATOR = undefined;
var _inquirer = require('inquirer');
var _inquirer2 = _interopRequireDefault(_inquirer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const SEPARATOR = exports.SEPARATOR = '';
function getChoices(items) {
return items.map(item => {
if (item === SEPARATOR) {
return new _inquirer2.default.Separator();
}
return {
name: item.toString(),
short: item.toString(),
value: item
};
});
}
/**
* Requests a selection of one of the given items from the user.
*
* @param {string} message The prompt message.
* @param {any[]} items The items to choose from.
*/
async function requestChoice(message, items) {
const answerName = 'requestChoice';
const answers = await _inquirer2.default.prompt([{
message,
name: answerName,
type: 'list',
choices: getChoices(items)
}]);
return answers[answerName];
}
exports.default = requestChoice;
;