@@ -7,6 +7,23 @@ const inquirer = require('inquirer');
7
7
const validate = input => input && input . length > 0 ;
8
8
const filter = input => ( input ? input . trim ( ) : '' ) ;
9
9
10
+ const pairValidation = input => {
11
+ if ( ! input ) {
12
+ return true ;
13
+ }
14
+
15
+ const pairs = input . split ( ',' ) ;
16
+ const res = pairs . map ( pair => {
17
+ const s = pair . split ( '=' ) ;
18
+ const [ key , val ] = s ;
19
+ return key && val ;
20
+ } ) ;
21
+ if ( res . some ( r => ! r ) ) {
22
+ return `Value should be specified in 'key=val,key2=val2' format!` ;
23
+ }
24
+ return true ;
25
+ } ;
26
+
10
27
exports . command = [ 'config' , 'init' ] ;
11
28
exports . describe = 'generate new config file for current project' ;
12
29
exports . builder = { } ;
@@ -79,6 +96,7 @@ exports.handler = async () => {
79
96
. join ( ', ' )
80
97
: '' ,
81
98
filter,
99
+ validate : pairValidation ,
82
100
} ) ;
83
101
prompts . push ( {
84
102
type : 'input' ,
@@ -90,6 +108,7 @@ exports.handler = async () => {
90
108
. join ( ', ' )
91
109
: '' ,
92
110
filter,
111
+ validate : pairValidation ,
93
112
} ) ;
94
113
prompts . push ( {
95
114
type : 'confirm' ,
@@ -102,23 +121,23 @@ exports.handler = async () => {
102
121
name : 'ratelimitPeriod' ,
103
122
message : 'Rate-limit period (in seconds)' ,
104
123
default : defaultConfig . rateLimit ? defaultConfig . rateLimit . period . replace ( 's' , '' ) : '1' ,
105
- filter : val => `${ val . trim ( ) } s` ,
124
+ filter : val => `${ val } s` ,
106
125
when : ( { enableRatelimit} ) => enableRatelimit ,
107
126
} ) ;
108
127
prompts . push ( {
109
128
type : 'input' ,
110
129
name : 'ratelimitAverage' ,
111
130
message : 'Rate-limit average request rate' ,
112
131
default : defaultConfig . rateLimit ? defaultConfig . rateLimit . average : '1' ,
113
- filter : val => Number ( val . trim ( ) ) ,
132
+ filter : val => Number ( val ) ,
114
133
when : ( { enableRatelimit} ) => enableRatelimit ,
115
134
} ) ;
116
135
prompts . push ( {
117
136
type : 'input' ,
118
137
name : 'ratelimitBurst' ,
119
138
message : 'Rate-limit burst request rate' ,
120
139
default : defaultConfig . rateLimit ? defaultConfig . rateLimit . burst : '5' ,
121
- filter : val => Number ( val . trim ( ) ) ,
140
+ filter : val => Number ( val ) ,
122
141
when : ( { enableRatelimit} ) => enableRatelimit ,
123
142
} ) ;
124
143
prompts . push ( {
0 commit comments