@@ -200,7 +200,7 @@ function parse (args, opts) {
200
200
setArg ( key , next )
201
201
i ++
202
202
} else {
203
- setArg ( key , defaultForType ( guessType ( key , flags ) ) )
203
+ setArg ( key , defaultValue ( key ) )
204
204
}
205
205
}
206
206
@@ -220,7 +220,7 @@ function parse (args, opts) {
220
220
setArg ( key , next )
221
221
i ++
222
222
} else {
223
- setArg ( key , defaultForType ( guessType ( key , flags ) ) )
223
+ setArg ( key , defaultValue ( key ) )
224
224
}
225
225
} else if ( arg . match ( / ^ - [ ^ - ] + / ) && ! arg . match ( negative ) ) {
226
226
letters = arg . slice ( 1 , - 1 ) . split ( '' )
@@ -267,7 +267,7 @@ function parse (args, opts) {
267
267
broken = true
268
268
break
269
269
} else {
270
- setArg ( letters [ j ] , defaultForType ( guessType ( letters [ j ] , flags ) ) )
270
+ setArg ( letters [ j ] , defaultValue ( letters [ j ] ) )
271
271
}
272
272
}
273
273
@@ -293,7 +293,7 @@ function parse (args, opts) {
293
293
setArg ( key , next )
294
294
i ++
295
295
} else {
296
- setArg ( key , defaultForType ( guessType ( key , flags ) ) )
296
+ setArg ( key , defaultValue ( key ) )
297
297
}
298
298
}
299
299
}
@@ -749,6 +749,18 @@ function parse (args, opts) {
749
749
} )
750
750
}
751
751
752
+ // make a best effor to pick a default value
753
+ // for an option based on name and type.
754
+ function defaultValue ( key ) {
755
+ if ( ! checkAllAliases ( key , flags . bools ) &&
756
+ ! checkAllAliases ( key , flags . counts ) &&
757
+ `${ key } ` in defaults ) {
758
+ return defaults [ key ]
759
+ } else {
760
+ return defaultForType ( guessType ( key ) )
761
+ }
762
+ }
763
+
752
764
// return a default value, given the type of a flag.,
753
765
// e.g., key of type 'string' will default to '', rather than 'true'.
754
766
function defaultForType ( type ) {
@@ -763,7 +775,7 @@ function parse (args, opts) {
763
775
}
764
776
765
777
// given a flag, enforce a default type.
766
- function guessType ( key , flags ) {
778
+ function guessType ( key ) {
767
779
var type = 'boolean'
768
780
769
781
if ( checkAllAliases ( key , flags . strings ) ) type = 'string'
0 commit comments