@@ -27,7 +27,7 @@ function parse (args, opts) {
27
27
'halt-at-non-option' : false ,
28
28
'strip-aliased' : false ,
29
29
'strip-dashed' : false ,
30
- 'ignore -unknown-options' : false
30
+ 'parse -unknown-options' : true
31
31
} , opts . configuration )
32
32
var defaults = opts . default || { }
33
33
var configObjects = opts . configObjects || [ ]
@@ -160,17 +160,17 @@ function parse (args, opts) {
160
160
} else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) && args . length > i + 1 ) {
161
161
args . splice ( i + 1 , 0 , m [ 2 ] )
162
162
i = eatArray ( i , m [ 1 ] , args )
163
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
163
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
164
164
setArg ( m [ 1 ] , m [ 2 ] )
165
165
} else {
166
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
166
+ argv . _ . push ( arg )
167
167
}
168
168
} else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
169
169
key = arg . match ( negatedBoolean ) [ 1 ]
170
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
170
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
171
171
setArg ( key , false )
172
172
} else {
173
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
173
+ argv . _ . push ( arg )
174
174
}
175
175
176
176
// -- seperated by space.
@@ -185,7 +185,7 @@ function parse (args, opts) {
185
185
// array format = '--foo a b c'
186
186
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
187
187
i = eatArray ( i , key , args )
188
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
188
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
189
189
next = flags . nargs [ key ] === 0 ? undefined : args [ i + 1 ]
190
190
191
191
if ( next !== undefined && ( ! next . match ( / ^ - / ) ||
@@ -201,24 +201,24 @@ function parse (args, opts) {
201
201
setArg ( key , defaultValue ( key ) )
202
202
}
203
203
} else {
204
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
204
+ argv . _ . push ( arg )
205
205
}
206
206
207
207
// dot-notation flag seperated by '='.
208
208
} else if ( arg . match ( / ^ - .\. .+ = / ) ) {
209
209
m = arg . match ( / ^ - ( [ ^ = ] + ) = ( [ \s \S ] * ) $ / )
210
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
210
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
211
211
setArg ( m [ 1 ] , m [ 2 ] )
212
212
} else {
213
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
213
+ argv . _ . push ( arg )
214
214
}
215
215
216
216
// dot-notation flag seperated by space.
217
217
} else if ( arg . match ( / ^ - .\. .+ / ) ) {
218
218
next = args [ i + 1 ]
219
219
key = arg . match ( / ^ - ( .\. .+ ) / ) [ 1 ]
220
220
221
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
221
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
222
222
if ( next !== undefined && ! next . match ( / ^ - / ) &&
223
223
! checkAllAliases ( key , flags . bools ) &&
224
224
! checkAllAliases ( key , flags . counts ) ) {
@@ -228,7 +228,7 @@ function parse (args, opts) {
228
228
setArg ( key , defaultValue ( key ) )
229
229
}
230
230
} else {
231
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
231
+ argv . _ . push ( arg )
232
232
}
233
233
} else if ( arg . match ( / ^ - [ ^ - ] + / ) && ! arg . match ( negative ) ) {
234
234
letters = arg . slice ( 1 , - 1 ) . split ( '' )
@@ -250,7 +250,7 @@ function parse (args, opts) {
250
250
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
251
251
args . splice ( i + 1 , 0 , value )
252
252
i = eatArray ( i , key , args )
253
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
253
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
254
254
setArg ( key , value )
255
255
} else {
256
256
unmatched . push ( key )
@@ -263,7 +263,7 @@ function parse (args, opts) {
263
263
}
264
264
265
265
if ( next === '-' ) {
266
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
266
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
267
267
setArg ( letters [ j ] , next )
268
268
} else {
269
269
unmatched . push ( letters [ j ] )
@@ -275,7 +275,7 @@ function parse (args, opts) {
275
275
// current letter is an alphabetic character and next value is a number
276
276
if ( / [ A - Z a - z ] / . test ( letters [ j ] ) &&
277
277
/ ^ - ? \d + ( \. \d * ) ? ( e - ? \d + ) ? $ / . test ( next ) ) {
278
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
278
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
279
279
setArg ( letters [ j ] , next )
280
280
} else {
281
281
unmatched . push ( letters [ j ] )
@@ -286,15 +286,15 @@ function parse (args, opts) {
286
286
}
287
287
288
288
if ( letters [ j + 1 ] && letters [ j + 1 ] . match ( / \W / ) ) {
289
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
289
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
290
290
setArg ( letters [ j ] , next )
291
291
} else {
292
292
unmatched . push ( letters [ j ] )
293
293
unmatched . push ( next )
294
294
}
295
295
broken = true
296
296
break
297
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
297
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
298
298
setArg ( letters [ j ] , defaultValue ( letters [ j ] ) )
299
299
} else {
300
300
unmatched . push ( letters [ j ] )
@@ -310,7 +310,7 @@ function parse (args, opts) {
310
310
// array format = '-f a b c'
311
311
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
312
312
i = eatArray ( i , key , args )
313
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
313
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
314
314
next = args [ i + 1 ]
315
315
316
316
if ( next !== undefined && ( ! / ^ ( - | - - ) [ ^ - ] / . test ( next ) ||
@@ -330,7 +330,7 @@ function parse (args, opts) {
330
330
}
331
331
}
332
332
if ( unmatched . length > 0 ) {
333
- argv . _ . push ( maybeCoerceNumber ( '_' , [ '-' , ...unmatched ] . join ( '' ) ) )
333
+ argv . _ . push ( [ '-' , ...unmatched ] . join ( '' ) )
334
334
}
335
335
} else if ( arg === '--' ) {
336
336
notFlags = args . slice ( i + 1 )
@@ -797,7 +797,8 @@ function parse (args, opts) {
797
797
798
798
function hasAnyFlag ( key ) {
799
799
var isSet = false
800
- var toCheck = [ ] . concat ( Object . values ( flags ) )
800
+ // XXX Switch to [].concat(...Object.values(flags)) once node.js 6 is dropped
801
+ var toCheck = [ ] . concat ( ...Object . keys ( flags ) . map ( k => flags [ k ] ) )
801
802
802
803
toCheck . forEach ( function ( flag ) {
803
804
if ( flag [ key ] ) isSet = flag [ key ]
0 commit comments