@@ -33,13 +33,7 @@ class ArgumentParser {
33
33
if ( this . parameters [ original ] ) {
34
34
this . parameters [ original ] . alias = alias ;
35
35
} else {
36
- throw (
37
- 'Attempted to add an alias "' +
38
- alias +
39
- '" for a non-existing parser argument "' +
40
- original +
41
- '".'
42
- ) ;
36
+ throw `Attempted to add an alias "${ alias } " for a non-existing parser argument "${ original } ".` ;
43
37
}
44
38
}
45
39
@@ -166,19 +160,19 @@ class ArgumentParser {
166
160
} else if ( typeof value === "number" ) {
167
161
value = ! ! value ;
168
162
} else {
169
- throw " Cannot convert value for " + name + " to boolean" ;
163
+ throw ` Cannot convert value for ${ name } to boolean.` ;
170
164
}
171
165
break ;
172
166
case "number" :
173
167
if ( typeof value === "string" ) {
174
168
value = parseInt ( value , 10 ) ;
175
169
if ( isNaN ( value ) ) {
176
- throw " Cannot convert value for " + name + " to number" ;
170
+ throw ` Cannot convert value for ${ name } to number.` ;
177
171
}
178
172
} else if ( typeof value === "boolean" ) {
179
173
value = value + 0 ;
180
174
} else {
181
- throw " Cannot convert value for " + name + " to number" ;
175
+ throw ` Cannot convert value for ${ name } to number.` ;
182
176
}
183
177
break ;
184
178
case "string" :
@@ -188,28 +182,25 @@ class ArgumentParser {
188
182
case "undefined" :
189
183
break ;
190
184
default :
191
- throw (
192
- "Do not know how to convert value for " +
193
- name +
194
- " to " +
185
+ throw `Do not know how to convert value for ${ name } of type ${ typeof value } to ${
195
186
spec . type
196
- ) ;
187
+ } .` ;
197
188
}
198
189
} catch ( e ) {
199
190
this . log . warn ( e ) ;
200
191
return null ;
201
192
}
202
193
203
194
if ( spec . choices && spec . choices . indexOf ( value ) === - 1 ) {
204
- this . log . warn ( " Illegal value for " + name + ": " + value ) ;
195
+ this . log . warn ( ` Illegal value for ${ name } : ${ value } .` ) ;
205
196
return null ;
206
197
}
207
198
return value ;
208
199
}
209
200
210
201
_set ( opts , name , value ) {
211
202
if ( ! ( name in this . parameters ) ) {
212
- this . log . debug ( " Ignoring value for unknown argument " + name ) ;
203
+ this . log . debug ( ` Ignoring value for unknown argument: ${ name } .` ) ;
213
204
return ;
214
205
}
215
206
const spec = this . parameters [ name ] ;
@@ -261,7 +252,7 @@ class ArgumentParser {
261
252
}
262
253
const matches = part . match ( this . named_param_pattern ) ;
263
254
if ( ! matches ) {
264
- this . log . warn ( " Invalid parameter: " + part + ": " + argstring ) ;
255
+ this . log . warn ( ` Invalid parameter: ${ part } : ${ argstring } .` ) ;
265
256
continue ;
266
257
}
267
258
const name = matches [ 1 ] ;
@@ -280,7 +271,7 @@ class ArgumentParser {
280
271
this . _set ( opts , name + "-" + field , subopt [ field ] ) ;
281
272
}
282
273
} else {
283
- this . log . warn ( " Unknown named parameter " + matches [ 1 ] ) ;
274
+ this . log . warn ( ` Unknown named parameter: ${ matches [ 1 ] } .` ) ;
284
275
continue ;
285
276
}
286
277
}
@@ -320,7 +311,7 @@ class ArgumentParser {
320
311
break ;
321
312
}
322
313
}
323
- if ( parts . length ) this . log . warn ( " Ignore extra arguments: " + parts . join ( " " ) ) ;
314
+ if ( parts . length ) this . log . warn ( ` Ignore extra arguments: ${ parts . join ( " " ) } .` ) ;
324
315
return opts ;
325
316
}
326
317
@@ -332,7 +323,7 @@ class ArgumentParser {
332
323
try {
333
324
return JSON . parse ( parameter ) ;
334
325
} catch ( e ) {
335
- this . log . warn ( " Invalid JSON argument found: " + parameter ) ;
326
+ this . log . warn ( ` Invalid JSON argument found: ${ parameter } .` ) ;
336
327
}
337
328
}
338
329
if ( parameter . match ( this . named_param_pattern ) ) {
@@ -352,41 +343,50 @@ class ArgumentParser {
352
343
353
344
_defaults ( $el ) {
354
345
const result = { } ;
355
- for ( const name in this . parameters )
356
- if ( typeof this . parameters [ name ] . value === "function" )
346
+ for ( const name in this . parameters ) {
347
+ if ( typeof this . parameters [ name ] . value === "function" ) {
357
348
try {
358
349
result [ name ] = this . parameters [ name ] . value ( $el , name ) ;
359
350
this . parameters [ name ] . type = typeof result [ name ] ;
360
351
} catch ( e ) {
361
- this . log . error ( " Default function for " + name + " failed." ) ;
352
+ this . log . error ( ` Default function for ${ name } failed.` ) ;
362
353
}
363
- else result [ name ] = this . parameters [ name ] . value ;
354
+ } else {
355
+ result [ name ] = this . parameters [ name ] . value ;
356
+ }
357
+ }
364
358
return result ;
365
359
}
366
360
367
361
_cleanupOptions ( options , group_options = true ) {
368
362
// Resolve references
369
363
for ( const name of Object . keys ( options ) ) {
370
364
const spec = this . parameters [ name ] ;
371
- if ( spec === undefined ) continue ;
365
+ if ( spec === undefined ) {
366
+ continue ;
367
+ }
372
368
373
369
if (
374
370
options [ name ] === spec . value &&
375
371
typeof spec . value === "string" &&
376
372
spec . value . slice ( 0 , 1 ) === "$"
377
- )
373
+ ) {
378
374
options [ name ] = options [ spec . value . slice ( 1 ) ] ;
375
+ }
379
376
}
380
377
if ( group_options ) {
381
378
// Move options into groups and do renames
382
379
for ( const name of Object . keys ( options ) ) {
383
380
const spec = this . parameters [ name ] ;
384
381
let target ;
385
- if ( spec === undefined ) continue ;
382
+ if ( spec === undefined ) {
383
+ continue ;
384
+ }
386
385
387
386
if ( spec . group ) {
388
- if ( typeof options [ spec . group ] !== "object" )
387
+ if ( typeof options [ spec . group ] !== "object" ) {
389
388
options [ spec . group ] = { } ;
389
+ }
390
390
target = options [ spec . group ] ;
391
391
} else {
392
392
target = options ;
@@ -430,9 +430,7 @@ class ArgumentParser {
430
430
) {
431
431
$possible_config_providers = $el ;
432
432
} else {
433
- $possible_config_providers = $el
434
- . parents ( "[" + this . attribute + "]" )
435
- . addBack ( ) ;
433
+ $possible_config_providers = $el . parents ( `[${ this . attribute } ]` ) . addBack ( ) ;
436
434
}
437
435
438
436
for ( const provider of $possible_config_providers ) {
0 commit comments