File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ function parse (args, opts) {
15
15
'camel-case-expansion' : true ,
16
16
'dot-notation' : true ,
17
17
'parse-numbers' : true ,
18
- 'boolean-negation' : true
18
+ 'boolean-negation' : true ,
19
+ 'duplicate-arguments-array' : true
19
20
} , opts . configuration )
20
21
var defaults = opts . default || { }
21
22
var configObjects = opts . configObjects || [ ]
@@ -544,8 +545,10 @@ function parse (args, opts) {
544
545
o [ key ] = value
545
546
} else if ( Array . isArray ( o [ key ] ) ) {
546
547
o [ key ] . push ( value )
547
- } else {
548
+ } else if ( configuration [ 'duplicate-arguments-array' ] ) {
548
549
o [ key ] = [ o [ key ] , value ]
550
+ } else {
551
+ o [ key ] = value
549
552
}
550
553
}
551
554
Original file line number Diff line number Diff line change @@ -1933,6 +1933,27 @@ describe('yargs-parser', function () {
1933
1933
expect ( parsed . dice ) . to . equal ( undefined )
1934
1934
} )
1935
1935
} )
1936
+
1937
+ describe ( 'duplicate arguments array' , function ( ) {
1938
+ it ( 'adds duplicate argument to array' , function ( ) {
1939
+ var parsed = parser ( '-x a -x b' , {
1940
+ configuration : {
1941
+ 'duplicate-arguments-array' : true
1942
+ }
1943
+ } )
1944
+
1945
+ parsed [ 'x' ] . should . deep . equal ( [ 'a' , 'b' ] )
1946
+ } )
1947
+ it ( 'keeps only last argument' , function ( ) {
1948
+ var parsed = parser ( '-x a -x b' , {
1949
+ configuration : {
1950
+ 'duplicate-arguments-array' : false
1951
+ }
1952
+ } )
1953
+
1954
+ parsed [ 'x' ] . should . equal ( 'b' )
1955
+ } )
1956
+ } )
1936
1957
} )
1937
1958
1938
1959
// addresses: https://github.com/yargs/yargs-parser/issues/41
You can’t perform that action at this time.
0 commit comments