假设我要提示用户使用“类型复选框”在数据库选项列表中进行选择:
{
type: 'checkbox',
name: 'databaseType',
message: `Which ${chalk.yellow('*type*')} of database(s) would you like to use?`,
choices: response => {
const databaseOpts = [
{
value: 'mysql',
name: 'MySQL'
},
{
value: 'cassandra',
name: 'Cassandra'
},
{
value: 'mongodb',
name: 'MongoDB'
}
];
return databaseOpts;
},
default: 0
},
在出现此初始提示后,我想获取他们选择的任何选项的响应,然后根据他们的选择再次提示他们输入数据库名称,然后将它们存储:
{
when: response => response.databaseType === 'mysql',
type: 'input',
name: 'selectedMySQL',
message: 'What is the name of your mysql database? ',
default: 'testmysql',
store: true
},
{
when: response => response.databaseType === 'cassandra',
type: 'input',
name: 'selectedCassandra',
message: 'What is the name of your cassandra database? ',
default: 'testcassandra',
store: true
},
{
when: response => response.databaseType === 'mongo',
type: 'input',
name: 'selectedMongo',
message: 'What is the name of your mongo database? ',
default: 'testmongo',
store: true
}
所需的样本输出:
例如,用户在databaseOpts中的选择:{mysql,mongodb}
然后它将询问:
1)您的mysql数据库的名称是什么?:
2)mongo数据库的名称是什么?:
用户分别输入名称,这些名称将存储在selectedMySQL和selectedMongo中。
我不熟悉yeoman语法,但这是我要实现的逻辑。请帮助,谢谢。
我尝试过:
when: response => response.databaseType.databaseOpts === 'mysql'
但是它仍然跳过响应提示。