-
Notifications
You must be signed in to change notification settings - Fork 1
/
example01.js
114 lines (98 loc) · 2.47 KB
/
example01.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var inquirer = require('inquirer');
inquirer.registerPrompt('checkbox-plus', require('./index'));
var Phone = [{
name: 'XiaoMi',
value: 'MI',
short: 'MI',
disabled: false,
type: 'cellphone'
}, {
name: 'Google',
value: 'Google',
short: 'Google',
disabled: true,
type: 'cellphone',
}, {
name: 'HUAWEI',
value: 'HUAWEI',
short: 'HUAWEI',
disabled: false,
type: 'cellphone',
}, {
name: 'iPhone',
value: 'iPhone',
short: 'iPhone',
disabled: false,
type: 'cellphone',
}];
var iPhone = [
{ name: 'iPhone 6s', type: 'name', disabled: true, },
{ name: 'iPhone 8 plus', type: 'name', disabled: true, },
{ name: 'iPhone X', type: 'name', disabled: true, },
]
var XiaoMi = [
{ name: 'MI note', type: 'name', },
{ name: 'MI plus', type: 'name', },
{ name: 'Mi 3', type: 'name' },
{ name: 'Mi 4', type: 'name' },
{ name: 'Mi 5', type: 'name' },
{ name: 'Mi 6', type: 'name' },
{ name: 'Mi 8', type: 'name', },
]
var MiNote = [
{ name: 'Mi note I', type: 'name' },
{ name: 'Mi note II' },
{ name: 'Mi note III' },
]
var Note = [
{ name: 1 },
{ name: 2 },
]
var MiPlus = [
{ name: 'Mi 3 plus' },
{ name: 'Mi 4 plus' },
{ name: 'Mi 5 plus' },
]
var i = 0;
inquirer.prompt([{
type: 'checkbox-plus',
name: 'phone',
message: 'select cellphone?',
pageSize: 4,
highlight: true,
default: ['iPhone', 'MI'],
footer: 'move up/down to select',
header: 'press space to select',
searching: 'searching....',
noresult: 'nothing..',
validate: function (answer) {
if (answer.length == 0) {
return 'You must choose at least one phone.';
}
return true;
},
source: function (answersSoFar, input) {
// input = input || '';
return Promise.resolve(Phone)
},
subsource: function (choice, type) {
if (choice.name === 'iPhone') {
return Promise.resolve(iPhone);
}
if (choice.name === 'XiaoMi') {
return Promise.resolve(XiaoMi);
}
if (choice.name === 'MI note') {
return Promise.resolve(MiNote);
}
if (choice.name === 'MI plus') {
return Promise.resolve(MiPlus);
}
if (choice.name === 'Mi note I') {
return Promise.resolve(Note);
}
return Promise.resolve([])
}
}]).then(function (answers) {
console.log(answers.phone);
}).catch(console.log)