我正在构建一个yeoman生成器,需要在回答提示时分配额外的值/答案。
我已经找到了一种方法来提示用户进行另一个问题,但我需要在后台自动分配预定义的答案 - 这样用户就不会看到它发生,也不会询问用户另一个问题。 下面是一个示例。此外,我需要对12个以上的值执行此操作,因此“when”命令不是理想的选择,因为我必须12次以上使用when语句。
我已经找到了一种方法来提示用户进行另一个问题,但我需要在后台自动分配预定义的答案 - 这样用户就不会看到它发生,也不会询问用户另一个问题。 下面是一个示例。此外,我需要对12个以上的值执行此操作,因此“when”命令不是理想的选择,因为我必须12次以上使用when语句。
this.prompt([{
type: 'list',
name: 'redWhite',
message: 'what colour',
choices: ['red', 'white', 'blue', 'black', 'green', 'yellow', 'purple', 'cyan', 'magenta', 'brown']
}, {
when: 'redWhite.red',
type: 'confirm',
name: 'blue',
message: 'Red is nice, but how about blue instead?'
},
/*So instead of prompting user again, just need to assign a predefined value here
, {
when: 'redWhite.red',
answer: redFooBar
}, */
{
when: 'redWhite.white',
type: 'confirm',
name: 'green',
message: 'White is nice, but how about green instead?'
}, {
name: 'otherColors',
message: 'What other colors do you like?'
}], function (answer) {
// answer = {
// redWhite: 'red',
// blue: false,
// green: false,
// otherColors: 'pink, purple-ish'
// };
});