如何将参数传递给询问者问题,以便我可以根据先前问题的值或提示之外的代码设置问题对象的值?
如果基于上一个问题的答案,我能看到实现此目的的唯一方法是嵌套查询器提示调用
const inquirer = require('inquirer');
function getPath(){
return {
'system1':`system1path`,
'system2':`system2path`,
'system3':`system3path`
}
}
inquirer.prompt([
{
type: 'list',
name: 'testSystem',
message: 'Which system do you want to run?',
choices: ['system1', 'system2', 'system3']
},
{
type: 'fuzzypath',
name: 'searchTestSuite',
excludePath: nodePath => nodePath.startsWith('node_modules'),
itemType: 'any',
rootPath: getPath()['< answer from question(testSystem) >'],
message: 'Select a target directory :',
default: `system1path`,
suggestOnly: false,
depthLimit: 6,
},
]).then(answers => {
console.log(answers);
});
预期结果:如果您选择 testSystem = system2 您应该得到 rootPath = system2Path ,而不嵌套查询器提示或使用when
函数(因为when
似乎正在处理布尔值)