File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -594,9 +594,9 @@ function parse (args, opts) {
594
594
function guessType ( key , flags ) {
595
595
var type = 'boolean'
596
596
597
- if ( flags . strings && flags . strings [ key ] ) type = 'string'
598
- else if ( flags . numbers && flags . numbers [ key ] ) type = 'number'
599
- else if ( flags . arrays && flags . arrays [ key ] ) type = 'array'
597
+ if ( checkAllAliases ( key , flags . strings ) ) type = 'string'
598
+ else if ( checkAllAliases ( key , flags . numbers ) ) type = 'number'
599
+ else if ( checkAllAliases ( key , flags . arrays ) ) type = 'array'
600
600
601
601
return type
602
602
}
Original file line number Diff line number Diff line change @@ -1903,4 +1903,34 @@ describe('yargs-parser', function () {
1903
1903
} )
1904
1904
} )
1905
1905
} )
1906
+
1907
+ // addresses: https://github.com/yargs/yargs-parser/issues/41
1908
+ it ( 'defaults to empty array if array option is provided no values' , function ( ) {
1909
+ var parsed = parser ( [ '-f' ] , {
1910
+ 'alias' : {
1911
+ 'f' : 'files'
1912
+ } ,
1913
+ 'array' : [ 'files' ]
1914
+ } )
1915
+ parsed . f . should . deep . equal ( [ ] )
1916
+ parsed . files . should . deep . equal ( [ ] )
1917
+
1918
+ parsed = parser ( [ '--files' ] , {
1919
+ 'alias' : {
1920
+ 'f' : 'files'
1921
+ } ,
1922
+ 'array' : [ 'files' ]
1923
+ } )
1924
+ parsed . f . should . deep . equal ( [ ] )
1925
+ parsed . files . should . deep . equal ( [ ] )
1926
+
1927
+ parsed = parser ( [ '-f' , '-y' ] , {
1928
+ 'alias' : {
1929
+ 'f' : 'files'
1930
+ } ,
1931
+ 'array' : [ 'files' ]
1932
+ } )
1933
+ parsed . f . should . deep . equal ( [ ] )
1934
+ parsed . files . should . deep . equal ( [ ] )
1935
+ } )
1906
1936
} )
You can’t perform that action at this time.
0 commit comments