@@ -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 || [ ]
@@ -169,17 +169,17 @@ function parse (args, opts) {
169
169
} else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) && args . length > i + 1 ) {
170
170
args . splice ( i + 1 , 0 , m [ 2 ] )
171
171
i = eatArray ( i , m [ 1 ] , args )
172
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
172
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
173
173
setArg ( m [ 1 ] , m [ 2 ] )
174
174
} else {
175
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
175
+ argv . _ . push ( arg )
176
176
}
177
177
} else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
178
178
key = arg . match ( negatedBoolean ) [ 1 ]
179
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
179
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
180
180
setArg ( key , false )
181
181
} else {
182
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
182
+ argv . _ . push ( arg )
183
183
}
184
184
185
185
// -- seperated by space.
@@ -194,7 +194,7 @@ function parse (args, opts) {
194
194
// array format = '--foo a b c'
195
195
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
196
196
i = eatArray ( i , key , args )
197
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
197
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
198
198
next = flags . nargs [ key ] === 0 ? undefined : args [ i + 1 ]
199
199
200
200
if ( next !== undefined && ( ! next . match ( / ^ - / ) ||
@@ -210,24 +210,24 @@ function parse (args, opts) {
210
210
setArg ( key , defaultValue ( key ) )
211
211
}
212
212
} else {
213
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
213
+ argv . _ . push ( arg )
214
214
}
215
215
216
216
// dot-notation flag seperated by '='.
217
217
} else if ( arg . match ( / ^ - .\. .+ = / ) ) {
218
218
m = arg . match ( / ^ - ( [ ^ = ] + ) = ( [ \s \S ] * ) $ / )
219
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
219
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( m [ 1 ] ) ) {
220
220
setArg ( m [ 1 ] , m [ 2 ] )
221
221
} else {
222
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
222
+ argv . _ . push ( arg )
223
223
}
224
224
225
225
// dot-notation flag seperated by space.
226
226
} else if ( arg . match ( / ^ - .\. .+ / ) ) {
227
227
next = args [ i + 1 ]
228
228
key = arg . match ( / ^ - ( .\. .+ ) / ) [ 1 ]
229
229
230
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
230
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
231
231
if ( next !== undefined && ! next . match ( / ^ - / ) &&
232
232
! checkAllAliases ( key , flags . bools ) &&
233
233
! checkAllAliases ( key , flags . counts ) ) {
@@ -237,7 +237,7 @@ function parse (args, opts) {
237
237
setArg ( key , defaultValue ( key ) )
238
238
}
239
239
} else {
240
- argv . _ . push ( maybeCoerceNumber ( '_' , arg ) )
240
+ argv . _ . push ( arg )
241
241
}
242
242
} else if ( arg . match ( / ^ - [ ^ - ] + / ) && ! arg . match ( negative ) ) {
243
243
letters = arg . slice ( 1 , - 1 ) . split ( '' )
@@ -259,7 +259,7 @@ function parse (args, opts) {
259
259
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
260
260
args . splice ( i + 1 , 0 , value )
261
261
i = eatArray ( i , key , args )
262
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
262
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
263
263
setArg ( key , value )
264
264
} else {
265
265
unmatched . push ( key )
@@ -272,7 +272,7 @@ function parse (args, opts) {
272
272
}
273
273
274
274
if ( next === '-' ) {
275
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
275
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
276
276
setArg ( letters [ j ] , next )
277
277
} else {
278
278
unmatched . push ( letters [ j ] )
@@ -284,7 +284,7 @@ function parse (args, opts) {
284
284
// current letter is an alphabetic character and next value is a number
285
285
if ( / [ A - Z a - z ] / . test ( letters [ j ] ) &&
286
286
/ ^ - ? \d + ( \. \d * ) ? ( e - ? \d + ) ? $ / . test ( next ) ) {
287
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
287
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
288
288
setArg ( letters [ j ] , next )
289
289
} else {
290
290
unmatched . push ( letters [ j ] )
@@ -295,15 +295,15 @@ function parse (args, opts) {
295
295
}
296
296
297
297
if ( letters [ j + 1 ] && letters [ j + 1 ] . match ( / \W / ) ) {
298
- if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
298
+ if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
299
299
setArg ( letters [ j ] , next )
300
300
} else {
301
301
unmatched . push ( letters [ j ] )
302
302
unmatched . push ( next )
303
303
}
304
304
broken = true
305
305
break
306
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
306
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( letters [ j ] ) ) {
307
307
setArg ( letters [ j ] , defaultValue ( letters [ j ] ) )
308
308
} else {
309
309
unmatched . push ( letters [ j ] )
@@ -319,7 +319,7 @@ function parse (args, opts) {
319
319
// array format = '-f a b c'
320
320
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
321
321
i = eatArray ( i , key , args )
322
- } else if ( ! configuration [ 'ignore -unknown-options' ] || hasAnyFlag ( key ) ) {
322
+ } else if ( configuration [ 'parse -unknown-options' ] || hasAnyFlag ( key ) ) {
323
323
next = args [ i + 1 ]
324
324
325
325
if ( next !== undefined && ( ! / ^ ( - | - - ) [ ^ - ] / . test ( next ) ||
@@ -339,7 +339,7 @@ function parse (args, opts) {
339
339
}
340
340
}
341
341
if ( unmatched . length > 0 ) {
342
- argv . _ . push ( maybeCoerceNumber ( '_' , [ '-' , ...unmatched ] . join ( '' ) ) )
342
+ argv . _ . push ( [ '-' , ...unmatched ] . join ( '' ) )
343
343
}
344
344
} else if ( arg === '--' ) {
345
345
notFlags = args . slice ( i + 1 )
@@ -808,7 +808,8 @@ function parse (args, opts) {
808
808
809
809
function hasAnyFlag ( key ) {
810
810
var isSet = false
811
- var toCheck = [ ] . concat ( Object . values ( flags ) )
811
+ // XXX Switch to [].concat(...Object.values(flags)) once node.js 6 is dropped
812
+ var toCheck = [ ] . concat ( ...Object . keys ( flags ) . map ( k => flags [ k ] ) )
812
813
813
814
toCheck . forEach ( function ( flag ) {
814
815
if ( flag [ key ] ) isSet = flag [ key ]
0 commit comments