Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 5cd6142

Browse files
authored
fix(cli): configure inquirer with correct initial values for attributesToDisplay (#530)
* fix(cli): configure inquirer with correct initial values for attributesToDisplay * test(cli): add test for answers default values
1 parent 9ffb469 commit 5cd6142

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const getAnswersDefaultValues = require('../getAnswersDefaultValues');
2+
3+
test('without attributesToDisplay in configuration', () => {
4+
const { attributesToDisplay } = getAnswersDefaultValues({}, {}, undefined);
5+
expect(attributesToDisplay).toBeUndefined();
6+
});
7+
8+
test('with attributesToDisplay in configuration', () => {
9+
const { attributesToDisplay } = getAnswersDefaultValues(
10+
{},
11+
{ attributesToDisplay: ['name'] },
12+
undefined
13+
);
14+
expect(attributesToDisplay).toEqual(['name']);
15+
});

src/cli/getAnswersDefaultValues.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function getAnswersDefaultValues(
2+
optionsFromArguments,
3+
configuration,
4+
template
5+
) {
6+
return {
7+
...optionsFromArguments,
8+
template,
9+
attributesToDisplay:
10+
configuration.attributesToDisplay &&
11+
configuration.attributesToDisplay.length > 0
12+
? configuration.attributesToDisplay
13+
: undefined,
14+
};
15+
};

src/cli/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
} = require('../utils');
1919
const getOptionsFromArguments = require('./getOptionsFromArguments');
2020
const getAttributesFromIndex = require('./getAttributesFromIndex');
21+
const getAnswersDefaultValues = require('./getAnswersDefaultValues');
2122
const isQuestionAsked = require('./isQuestionAsked');
2223
const {
2324
getConfiguration,
@@ -280,7 +281,7 @@ async function run() {
280281
getQuestions({ appName })[implementationType].filter(question =>
281282
isQuestionAsked({ question, args: optionsFromArguments })
282283
),
283-
{ ...optionsFromArguments, template }
284+
getAnswersDefaultValues(optionsFromArguments, configuration, template)
284285
);
285286

286287
const alternativeNames = createNameAlternatives({

0 commit comments

Comments
 (0)