Move output from settings to questions

This commit is contained in:
Will Boyd
2025-01-31 13:11:07 -05:00
parent 865795cf11
commit cf338813f1
5 changed files with 25 additions and 17 deletions
+11 -5
View File
@@ -27,8 +27,10 @@ export async function getConfig() {
if (commandLineAnswers.wizard) {
console.log('\nStarting wizard...');
// run wizard for remaining config options
const wizardQuestions = questions.all.filter((question) => !(camelcase(question.name) in commandLineAnswers));
// run wizard for questions with prompts that were not answered via the command line
const wizardQuestions = questions.all.filter((question) => {
return question.prompt && !(camelcase(question.name) in commandLineAnswers);
});
wizardAnswers = await getWizardAnswers(wizardQuestions, commandLineAnswers);
} else {
console.log('\nSkipping wizard...');
@@ -47,6 +49,10 @@ function getCommandLineAnswers(questions) {
const option = new commander.Option('--' + question.name + ' <' + question.type + '>', question.description);
option.default(question.default);
if (!question.description) {
option.hideHelp();
}
if (question.choices && question.type !== 'boolean') {
// let commander handle non-boolean multiple choice validation
option.choices(question.choices.map((choice) => choice.value));
@@ -68,12 +74,12 @@ function getCommandLineAnswers(questions) {
continue;
}
if (answers.wizard) {
// remove this default answer so the wizard will ask about it later
const question = questions.find((question) => camelcase(question.name) === key);
if (answers.wizard && question.prompt) {
// remove this default answer, allowing the wizard to ask about it later
delete answers[key];
} else {
// normalize and validate default answer
const question = questions.find((question) => camelcase(question.name) === key);
answers[key] = normalize(value, question.type, (errorMessage) => {
// this is formatted to match how commander displays other errors
commander.program.error(`error: option '--${question.name} <${question.type}>' argument '${value}' is invalid. ${errorMessage}`);