@@ -10,16 +10,6 @@ const helper = require('./helper')
10
10
const constant = require ( './constants' )
11
11
12
12
function processArgs ( argv , options , fs , path ) {
13
- if ( argv . help ) {
14
- console . log ( yargs . help ( ) )
15
- process . exit ( 0 )
16
- }
17
-
18
- if ( argv . version ) {
19
- console . log ( `Karma version: ${ constant . VERSION } ` )
20
- process . exit ( 0 )
21
- }
22
-
23
13
// TODO(vojta): warn/throw when unknown argument (probably mispelled)
24
14
Object . getOwnPropertyNames ( argv ) . forEach ( function ( name ) {
25
15
let argumentValue = argv [ name ]
@@ -130,6 +120,10 @@ function processArgs (argv, options, fs, path) {
130
120
131
121
options . configFile = configFile ? path . resolve ( configFile ) : null
132
122
123
+ if ( options . cmd === 'run' ) {
124
+ options . clientArgs = parseClientArgs ( process . argv )
125
+ }
126
+
133
127
return options
134
128
}
135
129
@@ -151,39 +145,44 @@ function argsBeforeDoubleDash (argv) {
151
145
return idx === - 1 ? argv : argv . slice ( 0 , idx )
152
146
}
153
147
154
- function describeShared ( ) {
155
- yargs
148
+ function describeRoot ( ) {
149
+ return yargs
156
150
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
151
+ 'Run --help with particular command to see its description and available options.\n\n' +
157
152
'Usage:\n' +
158
- ' $0 <command>\n\n' +
159
- 'Commands:\n' +
160
- ' start [<configFile>] [<options>] Start the server / do single run.\n' +
161
- ' init [<configFile>] Initialize a config file.\n' +
162
- ' run [<options>] [ -- <clientArgs>] Trigger a test run.\n' +
163
- ' completion Shell completion for karma.\n\n' +
164
- 'Run --help with particular command to see its description and available options.' )
153
+ ' $0 <command>' )
154
+ . command ( 'init' , 'Initialize a config file.' , describeInit )
155
+ . command ( 'start' , 'Start the server / do a single run.' , describeStart )
156
+ . command ( 'run' , 'Trigger a test run.' , describeRun )
157
+ . command ( 'stop' , 'Stop the server.' , describeStop )
158
+ . command ( 'completion' , 'Shell completion for karma.' , describeCompletion )
159
+ . demandCommand ( 1 , 'Command not specified.' )
160
+ . strictCommands ( )
165
161
. describe ( 'help' , 'Print usage and options.' )
166
162
. describe ( 'version' , 'Print current version.' )
167
163
}
168
164
169
- function describeInit ( ) {
165
+ function describeInit ( yargs ) {
170
166
yargs
171
167
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
172
168
'INIT - Initialize a config file.\n\n' +
173
169
'Usage:\n' +
174
- ' $0 init [<configFile>]' )
170
+ ' $0 init [configFile]' )
171
+ . strictCommands ( false )
172
+ . version ( false )
175
173
. describe ( 'log-level' , '<disable | error | warn | info | debug> Level of logging.' )
176
174
. describe ( 'colors' , 'Use colors when reporting and printing logs.' )
177
175
. describe ( 'no-colors' , 'Do not use colors when reporting or printing logs.' )
178
- . describe ( 'help' , 'Print usage and options.' )
179
176
}
180
177
181
- function describeStart ( ) {
178
+ function describeStart ( yargs ) {
182
179
yargs
183
180
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
184
181
'START - Start the server / do a single run.\n\n' +
185
182
'Usage:\n' +
186
- ' $0 start [<configFile>] [<options>]' )
183
+ ' $0 start [configFile]' )
184
+ . strictCommands ( false )
185
+ . version ( false )
187
186
. describe ( 'port' , '<integer> Port where the server is running.' )
188
187
. describe ( 'auto-watch' , 'Auto watch source files and run on change.' )
189
188
. describe ( 'detached' , 'Detach the server.' )
@@ -201,93 +200,57 @@ function describeStart () {
201
200
. describe ( 'no-fail-on-empty-test-suite' , 'Do not fail on empty test suite.' )
202
201
. describe ( 'fail-on-failing-test-suite' , 'Fail on failing test suite.' )
203
202
. describe ( 'no-fail-on-failing-test-suite' , 'Do not fail on failing test suite.' )
204
- . describe ( 'help' , 'Print usage and options.' )
205
203
}
206
204
207
- function describeRun ( ) {
205
+ function describeRun ( yargs ) {
208
206
yargs
209
207
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
210
208
'RUN - Run the tests (requires running server).\n\n' +
211
209
'Usage:\n' +
212
- ' $0 run [<configFile>] [<options>] [ -- <clientArgs>]' )
210
+ ' $0 run [configFile] [-- <clientArgs>]' )
211
+ . strictCommands ( false )
212
+ . version ( false )
213
213
. describe ( 'port' , '<integer> Port where the server is listening.' )
214
214
. describe ( 'no-refresh' , 'Do not re-glob all the patterns.' )
215
215
. describe ( 'fail-on-empty-test-suite' , 'Fail on empty test suite.' )
216
216
. describe ( 'no-fail-on-empty-test-suite' , 'Do not fail on empty test suite.' )
217
- . describe ( 'help' , 'Print usage.' )
218
217
. describe ( 'log-level' , '<disable | error | warn | info | debug> Level of logging.' )
219
218
. describe ( 'colors' , 'Use colors when reporting and printing logs.' )
220
219
. describe ( 'no-colors' , 'Do not use colors when reporting or printing logs.' )
221
220
}
222
221
223
- function describeStop ( ) {
222
+ function describeStop ( yargs ) {
224
223
yargs
225
224
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
226
225
'STOP - Stop the server (requires running server).\n\n' +
227
226
'Usage:\n' +
228
- ' $0 run [<configFile>] [<options>]' )
227
+ ' $0 stop [configFile]' )
228
+ . strictCommands ( false )
229
+ . version ( false )
229
230
. describe ( 'port' , '<integer> Port where the server is listening.' )
230
231
. describe ( 'log-level' , '<disable | error | warn | info | debug> Level of logging.' )
231
- . describe ( 'help' , 'Print usage.' )
232
232
}
233
233
234
- function describeCompletion ( ) {
234
+ function describeCompletion ( yargs ) {
235
235
yargs
236
236
. usage ( 'Karma - Spectacular Test Runner for JavaScript.\n\n' +
237
237
'COMPLETION - Bash/ZSH completion for karma.\n\n' +
238
238
'Installation:\n' +
239
- ' $0 completion >> ~/.bashrc\n' )
240
- . describe ( 'help' , 'Print usage.' )
239
+ ' $0 completion >> ~/.bashrc' )
240
+ . strictCommands ( false )
241
+ . version ( false )
241
242
}
242
243
243
244
function printRunnerProgress ( data ) {
244
245
process . stdout . write ( data )
245
246
}
246
247
247
- exports . process = function ( ) {
248
- const argv = yargs . parse ( argsBeforeDoubleDash ( process . argv . slice ( 2 ) ) )
249
- const options = {
250
- cmd : argv . _ . shift ( )
251
- }
252
-
253
- switch ( options . cmd ) {
254
- case 'start' :
255
- describeStart ( )
256
- break
257
-
258
- case 'run' :
259
- describeRun ( )
260
- options . clientArgs = parseClientArgs ( process . argv )
261
- break
262
-
263
- case 'stop' :
264
- describeStop ( )
265
- break
266
-
267
- case 'init' :
268
- describeInit ( )
269
- break
270
-
271
- case 'completion' :
272
- describeCompletion ( )
273
- break
274
-
275
- default :
276
- describeShared ( )
277
- if ( ! options . cmd ) {
278
- processArgs ( argv , options , fs , path )
279
- console . error ( 'Command not specified.' )
280
- } else {
281
- console . error ( 'Unknown command "' + options . cmd + '".' )
282
- }
283
- yargs . showHelp ( )
284
- process . exit ( 1 )
285
- }
286
-
287
- return processArgs ( argv , options , fs , path )
248
+ exports . process = ( ) => {
249
+ const argv = describeRoot ( ) . parse ( argsBeforeDoubleDash ( process . argv . slice ( 2 ) ) )
250
+ return processArgs ( argv , { cmd : argv . _ . shift ( ) } , fs , path )
288
251
}
289
252
290
- exports . run = function ( ) {
253
+ exports . run = ( ) => {
291
254
const config = exports . process ( )
292
255
293
256
switch ( config . cmd ) {
0 commit comments