Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 can set answers through CLI in default mode
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
streamich committed Jan 20, 2020
1 parent 49636ca commit 99238c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/createQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ const creators = {
type: qType
};

const createQuestions = (state) => {
const questions = state.config.questions.map((name) => {
const question = creators[name].createQuestion(state);
const createQuestions = (state, cliAnswers) => {
const questions = state.config.questions
.filter((name) => cliAnswers[name] === undefined)
.map((name) => {
const question = creators[name].createQuestion(state);

return question;
});
return question;
});

return questions.filter(Boolean);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/questions/subject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ exports.createQuestion = (state) => {
leadingLabel: (answers) => {
let scope = '';

if (answers.scope && (answers.scope !== 'none')) {
if (answers.scope && answers.scope !== 'none') {
scope = `(${answers.scope})`;
}

return `${answers.type}${scope}:`;
return `${state.answers.type || answers.type}${scope}:`;
},

// Minus 3 chars are for emoji + space.
Expand Down
8 changes: 6 additions & 2 deletions lib/runInteractiveQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ inquirer.registerPrompt('autocomplete', AutocompletePrompt);
// promptQuestions = promptQuestions.concat(createPackagesQuestion(allPackages, changedPackages));
// }

const runInteractiveQuestions = async (state) => {
const questions = createQuestions(state);
const runInteractiveQuestions = async (state, cliAnswers) => {
Object.keys(cliAnswers).forEach((key) => {
state.answers[key] = cliAnswers[key];
});

const questions = createQuestions(state, cliAnswers);
const answers = await inquirer.prompt(questions);

Object.keys(state.answers).forEach((key) => {
Expand Down

0 comments on commit 99238c2

Please sign in to comment.