File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ const defaultValue = (type?: "boolean" | "string" | "array") => {
5656
5757const coerce = ( value ?: string , type ?: "string" | "boolean" | "array" ) => {
5858 if ( type === "string" ) return value ;
59- if ( type === "boolean" ) return ! ! value ;
59+ if ( type === "boolean" ) return value === undefined ? true : value === 'true' ;
6060
6161 if ( ! value ) return value ;
6262 if ( value . length > 3 && BOOL_RE . test ( value ) ) return value === "true" ;
Original file line number Diff line number Diff line change @@ -257,3 +257,24 @@ describe("special cases", () => {
257257 expect ( result ) . toEqual ( output ) ;
258258 } ) ;
259259} ) ;
260+
261+ describe ( "boolean flags" , ( ) => {
262+ it ( "should handle long-form boolean flags correctly" , ( ) => {
263+ const input = [ "--add" ] ;
264+ const opts = {
265+ boolean : [ 'add' ]
266+ } ;
267+ const output = { _ : [ ] , add : true } ;
268+ expect ( parse ( input , opts ) ) . toEqual ( output ) ;
269+ } ) ;
270+
271+ it ( "should handle alias boolean flags correctly" , ( ) => {
272+ const input = [ "-a" ] ;
273+ const opts = {
274+ boolean : [ 'add' ] ,
275+ alias : { a : 'add' }
276+ } ;
277+ const output = { _ : [ ] , add : true } ;
278+ expect ( parse ( input , opts ) ) . toEqual ( output ) ;
279+ } ) ;
280+ } ) ;
You can’t perform that action at this time.
0 commit comments