1
1
#! /usr/bin/env node
2
2
3
- var todo = process . argv [ 2 ] ,
4
- path = require ( 'path' ) ,
5
- config ;
3
+ var yargs = require ( 'yargs' )
4
+ . command ( 'init [preset] [path]' , 'initialise browserstack.json with preset and test runner path' , function ( yargs ) {
5
+ return yargs . option ( 'preset' , {
6
+ type : 'string' ,
7
+ default : 'default' ,
8
+ description : 'name of preset json file(without extension)(present in node_modules/browserstack-runner/presets to be used while initiating'
9
+ } )
10
+ . option ( 'path' , {
11
+ type : 'string' ,
12
+ default : '/path/to/test/runner' ,
13
+ description : 'path to test runner to be inserted in browserstack.json'
14
+ } )
15
+ } )
16
+ . option ( 'browsers' , {
17
+ alias : 'b' ,
18
+ type : 'array' ,
19
+ description : 'list of space separatedbrowsers keys as described in json file'
20
+ } )
21
+ . option ( 'path' , {
22
+ type : 'string' ,
23
+ description : 'path to test file'
24
+ } )
25
+ . option ( 'version' , {
26
+ alias : 'V' ,
27
+ description : 'browserstack-runner version'
28
+ } )
29
+ . option ( 'pid' , {
30
+ type : 'string' ,
31
+ description : 'path to pid file'
32
+ } )
33
+ . option ( 'verbose' , {
34
+ alias : 'v' ,
35
+ description : 'verbose logging'
36
+ } ) . argv ;
6
37
7
- if ( process . argv . indexOf ( '-- verbose') !== - 1 ) {
38
+ if ( yargs [ ' verbose'] ) {
8
39
global . logLevel = process . env . LOG_LEVEL || 'debug' ;
9
40
} else {
10
41
global . logLevel = 'info' ;
11
42
}
43
+ var path = require ( 'path' ) ,
44
+ config ;
12
45
13
- if ( todo === 'init' ) {
46
+ if ( yargs [ '_' ] . indexOf ( 'init' ) !== - 1 ) {
47
+ module . exports . preset = yargs [ 'preset' ] ;
48
+ module . exports . path = yargs [ 'path' ] ;
14
49
require ( './init.js' ) ;
15
50
return ;
16
- } else if ( todo === '--version' ) {
17
- require ( './version.js' ) ;
18
- return ;
19
51
}
20
52
21
53
var config_path = process . env . BROWSERSTACK_JSON || 'browserstack.json' ;
@@ -37,17 +69,28 @@ try {
37
69
}
38
70
39
71
// extract a path to file to store tunnel pid
40
- var pid = process . argv . find ( function ( param ) { return param . indexOf ( '--pid' ) !== - 1 ; } ) ;
41
-
42
- if ( pid ) {
43
- var extracted_path = / - - p i d = ( [ \w \/ \. - ] + ) / g. exec ( pid ) ;
44
- if ( extracted_path ) {
45
- config . tunnel_pid_file = extracted_path [ 1 ] ;
72
+ if ( yargs [ 'pid' ] ) {
73
+ if ( yargs [ 'pid' ] . length > 0 ) {
74
+ config . tunnel_pid_file = yargs [ 'pid' ] ;
46
75
} else {
47
76
console . error ( 'Error while parsing flag --pid. Usage: --pid=/path/to/file' ) ;
48
77
}
49
78
}
50
79
80
+ // filter browsers according to from command line arguments
81
+ if ( yargs [ 'browsers' ] ) {
82
+ if ( yargs [ 'browsers' ] . length > 0 ) {
83
+ config . browsers = config . browsers . filter ( function ( browser ) {
84
+ return yargs [ 'browsers' ] . indexOf ( browser [ 'cli_key' ] ) !== - 1 ;
85
+ } ) ;
86
+ } else {
87
+ console . error ( 'No browser keys specified. Usage --browsers <key1> <key2> ...' ) ;
88
+ }
89
+ }
90
+
91
+ // test file path from cli arguments
92
+ config . test_path = yargs [ 'path' ] || config . test_path ;
93
+
51
94
var runner = require ( './cli.js' ) ;
52
95
runner . run ( config , function ( err ) {
53
96
if ( err ) {
0 commit comments