@@ -27,7 +27,7 @@ const subCommands = {
27
27
} ;
28
28
29
29
function Command ( projectBaseDir , examplesDir , deps ) {
30
- const { print, platform, Jasmine, ParallelRunner} = deps ;
30
+ const { print, platform, terminalColumns , Jasmine, ParallelRunner} = deps ;
31
31
const isWindows = platform ( ) === 'win32' ;
32
32
33
33
this . projectBaseDir = isWindows ? unWindows ( projectBaseDir ) : projectBaseDir ;
@@ -54,7 +54,8 @@ function Command(projectBaseDir, examplesDir, deps) {
54
54
projectBaseDir,
55
55
specDir : command . specDir ,
56
56
examplesDir : examplesDir ,
57
- print
57
+ print,
58
+ terminalColumns
58
59
} ) ;
59
60
} else {
60
61
const options = parseOptions ( args , isWindows ) ;
@@ -66,7 +67,7 @@ function Command(projectBaseDir, examplesDir, deps) {
66
67
}
67
68
68
69
print ( '' ) ;
69
- help ( { print : print } ) ;
70
+ help ( { print, terminalColumns } ) ;
70
71
} else {
71
72
await runJasmine ( Jasmine , ParallelRunner , projectBaseDir , options ) ;
72
73
}
@@ -284,39 +285,90 @@ function installExamples(options) {
284
285
) ;
285
286
}
286
287
287
- function help ( options ) {
288
- const print = options . print ;
289
- print ( 'Usage: jasmine [command] [options] [files] [--]' ) ;
288
+ function help ( deps ) {
289
+ const print = deps . print ;
290
+ let terminalColumns = deps . terminalColumns || 80 ;
291
+
292
+ print ( wrap ( terminalColumns , 'Usage: jasmine [command] [options] [files] [--]' ) ) ;
290
293
print ( '' ) ;
291
294
print ( 'Commands:' ) ;
292
295
Object . keys ( subCommands ) . forEach ( function ( cmd ) {
293
296
let commandNameText = cmd ;
294
297
if ( subCommands [ cmd ] . alias ) {
295
298
commandNameText = commandNameText + ',' + subCommands [ cmd ] . alias ;
296
299
}
297
- print ( '%s\t%s' , lPad ( commandNameText , 10 ) , subCommands [ cmd ] . description ) ;
300
+ print ( wrapWithIndent ( terminalColumns , lPad ( commandNameText , 10 ) + ' ' , subCommands [ cmd ] . description ) ) ;
298
301
} ) ;
299
302
print ( '' ) ;
300
- print ( 'If no command is given, jasmine specs will be run' ) ;
303
+ print ( wrap ( terminalColumns , 'If no command is given, Jasmine specs will be run.' ) ) ;
301
304
print ( '' ) ;
302
305
print ( '' ) ;
303
306
304
307
print ( 'Options:' ) ;
305
- print ( '%s\tRun in parallel with N workers' , lPad ( '--parallel=N' , 18 ) ) ;
306
- print ( '%s\tRun in parallel with an automatically chosen number of workers' , lPad ( '--parallel=auto' , 18 ) ) ;
307
- print ( '%s\tturn off color in spec output' , lPad ( '--no-color' , 18 ) ) ;
308
- print ( '%s\tforce turn on color in spec output' , lPad ( '--color' , 18 ) ) ;
309
- print ( '%s\tfilter specs to run only those that match the given string' , lPad ( '--filter=' , 18 ) ) ;
310
- print ( '%s\tload helper files that match the given string' , lPad ( '--helper=' , 18 ) ) ;
311
- print ( '%s\tload module that match the given string' , lPad ( '--require=' , 18 ) ) ;
312
- print ( '%s\tstop Jasmine execution on spec failure' , lPad ( '--fail-fast' , 18 ) ) ;
313
- print ( '%s\tpath to your optional jasmine.json' , lPad ( '--config=' , 18 ) ) ;
314
- print ( '%s\tpath to reporter to use instead of the default Jasmine reporter' , lPad ( '--reporter=' , 18 ) ) ;
315
- print ( '%s\tprint information that may be useful for debugging configuration' , lPad ( '--verbose' , 18 ) ) ;
316
- print ( '%s\tmarker to signal the end of options meant for Jasmine' , lPad ( '--' , 18 ) ) ;
308
+
309
+ const options = [
310
+ { syntax : '--parallel=N' , help : 'Run in parallel with N workers' } ,
311
+ { syntax : '--parallel=auto' , help : 'Run in parallel with an automatically chosen number of workers' } ,
312
+ { syntax : '--no-color' , help : 'turn off color in spec output' } ,
313
+ { syntax : '--color' , help : 'force turn on color in spec output' } ,
314
+ { syntax : '--filter=' , help : 'filter specs to run only those that match the given string' } ,
315
+ { syntax : '--helper=' , help : 'load helper files that match the given string' } ,
316
+ { syntax : '--require=' , help : 'load module that matches the given string' } ,
317
+ { syntax : '--fail-fast' , help : 'stop Jasmine execution on spec failure' } ,
318
+ { syntax : '--config=' , help : 'path to the Jasmine configuration file' } ,
319
+ { syntax : '--reporter=' , help : 'path to reporter to use instead of the default Jasmine reporter' } ,
320
+ { syntax : '--verbose' , help : 'print information that may be useful for debugging configuration' } ,
321
+ { syntax : '--' , help : 'marker to signal the end of options meant for Jasmine' } ,
322
+ ] ;
323
+
324
+ for ( const o of options ) {
325
+ print ( wrapWithIndent ( terminalColumns , lPad ( o . syntax , 18 ) + ' ' , o . help ) ) ;
326
+ }
327
+
317
328
print ( '' ) ;
318
- print ( 'The given arguments take precedence over options in your jasmine.json' ) ;
319
- print ( 'The path to your optional jasmine.json can also be configured by setting the JASMINE_CONFIG_PATH environment variable' ) ;
329
+ print ( wrap ( terminalColumns ,
330
+ 'The given arguments take precedence over options in your jasmine.json.' ) ) ;
331
+ print ( wrap ( terminalColumns ,
332
+ 'The path to your optional jasmine.json can also be configured by setting the JASMINE_CONFIG_PATH environment variable.' ) ) ;
333
+ }
334
+
335
+ function wrapWithIndent ( cols , prefix , suffix ) {
336
+ const lines = wrap2 ( cols - prefix . length , suffix ) ;
337
+ const indent = lPad ( '' , prefix . length ) ;
338
+ return prefix + lines . join ( '\n' + indent ) ;
339
+ }
340
+
341
+ function wrap ( cols , input ) {
342
+ return wrap2 ( cols , input ) . join ( '\n' ) ;
343
+ }
344
+
345
+ function wrap2 ( cols , input ) {
346
+ let lines = [ ] ;
347
+ let start = 0 ;
348
+
349
+ while ( start < input . length ) {
350
+ const splitAt = indexOfLastSpaceInRange ( start , start + cols , input ) ;
351
+
352
+ if ( splitAt === - 1 || input . length - start <= cols ) {
353
+ lines . push ( input . substring ( start ) ) ;
354
+ break ;
355
+ } else {
356
+ lines . push ( input . substring ( start , splitAt ) ) ;
357
+ start = splitAt + 1 ;
358
+ }
359
+ }
360
+
361
+ return lines ;
362
+ }
363
+
364
+ function indexOfLastSpaceInRange ( start , end , s ) {
365
+ for ( let i = end ; i >= start ; i -- ) {
366
+ if ( s [ i ] === ' ' ) {
367
+ return i ;
368
+ }
369
+ }
370
+
371
+ return - 1 ;
320
372
}
321
373
322
374
function version ( options ) {
0 commit comments