diff --git a/packages/nx/src/utils/params.spec.ts b/packages/nx/src/utils/params.spec.ts index 15316ade7a98ee..ced3674210bfdf 100644 --- a/packages/nx/src/utils/params.spec.ts +++ b/packages/nx/src/utils/params.spec.ts @@ -1743,6 +1743,44 @@ describe('params', () => { ]); }); + it('should use a multiselect if type is array and x-prompt uses shorthand', () => { + const prompts = getPromptsForSchema( + {}, + { + properties: { + pets: { + type: 'array', + 'x-prompt': 'What kind of pets do you have?', + items: { + enum: ['cat', 'dog', 'fish'], + }, + }, + }, + }, + { + version: 2, + projects: {}, + } + ); + + expect(prompts).toMatchInlineSnapshot(` + [ + { + "choices": [ + "cat", + "dog", + "fish", + ], + "limit": 10, + "message": "What kind of pets do you have?", + "name": "pets", + "type": "multiselect", + "validate": [Function], + }, + ] + `); + }); + describe('Project prompts', () => { it('should use an autocomplete prompt for a property named project', () => { const prompts = getPromptsForSchema( diff --git a/packages/nx/src/utils/params.ts b/packages/nx/src/utils/params.ts index 7fb629e79b8527..7d46a27cdc079e 100644 --- a/packages/nx/src/utils/params.ts +++ b/packages/nx/src/utils/params.ts @@ -785,10 +785,23 @@ export function getPromptsForSchema( // Normalize x-prompt if (typeof v['x-prompt'] === 'string') { const message = v['x-prompt']; - v['x-prompt'] = { - type: v.type === 'boolean' ? 'confirm' : 'input', - message, - }; + if (v.type === 'boolean') { + v['x-prompt'] = { + type: 'confirm', + message, + }; + } else if (v.type === 'array' && v.items?.enum) { + v['x-prompt'] = { + type: 'multiselect', + items: v.items.enum, + message, + }; + } else { + v['x-prompt'] = { + type: 'input', + message, + }; + } } question.message = v['x-prompt'].message;