eddi-cli
Version:
Command line interface to make project-based editing of EDDI personalities possible.
44 lines (37 loc) • 1.01 kB
JavaScript
const inquirer = require('inquirer');
function getType(option) {
if (option.choices) {
return 'list';
}
if (option.type === 'number') {
return 'number';
}
if (option.type === 'boolean') {
return 'confirm';
}
return 'input';
}
async function askQuestions(argv, options) {
const questions = Object.entries(options).reduce((acc, [key, option]) => {
const hasDefaulted = argv.defaulted[key] === true;
if (!option.requestArg || (!hasDefaulted && argv[key])) {
return acc;
}
acc.push({
type: getType(option),
name: key,
message: option.question,
choices: option.questionChoices || option.choices,
validate: option.validate,
default: option.default,
when: option.when,
});
return acc;
}, []);
if (!questions.length) {
return argv;
}
const answers = await inquirer.prompt(questions);
return Object.assign({}, argv, answers);
}
module.exports = askQuestions;