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") => {
56
56
57
57
const coerce = ( value ?: string , type ?: "string" | "boolean" | "array" ) => {
58
58
if ( type === "string" ) return value ;
59
- if ( type === "boolean" ) return ! ! value ;
59
+ if ( type === "boolean" ) return value === undefined ? true : value === 'true' ;
60
60
61
61
if ( ! value ) return value ;
62
62
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", () => {
257
257
expect ( result ) . toEqual ( output ) ;
258
258
} ) ;
259
259
} ) ;
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