-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexamples.js
48 lines (43 loc) · 1.39 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const inquirer = require('inquirer');
inquirer.registerPrompt('selectLine', require('../index'));
const firstQuestion = {
type: 'selectLine',
message: 'Where add line?',
name: 'line',
choices: ['first', 'second', 'third', 'fourth'],
};
const secondQuestion = {
type: 'selectLine',
message: 'After which line?',
name: 'after',
choices: ['line 1', 'line 2', 'last line'],
placeholder: index => index === 0 ? 'At first line' : `After: '${secondQuestion.choices[index - 1]}'`,
};
const thirdQuestion = {
type: 'selectLine',
message: 'How should it looks like?',
name: 'result',
choices: answers => index => {
switch (index) {
case 0:
return ['second line when selected first', 'third line when selected first'];
case 1:
return ['first line when selected second', 'third line when selected second'];
case 2:
return ['first line when selected third', 'second line when selected third'];
default:
return ['first line', 'second line'];
}
},
placeholder: 'NEW ITEM',
};
inquirer.prompt([
firstQuestion,
secondQuestion,
thirdQuestion,
]).then(function(answers) {
console.log('Where add line?', answers.line); // eslint-disable-line no-console
console.log('After which line?', answers.after); // eslint-disable-line no-console
console.log('How looks?', answers.result); // eslint-disable-line no-console
});