Skip to content

Commit

Permalink
refactor(flags): refactor boolean type
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Mar 22, 2020
1 parent 8228ac1 commit 10997f6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/flags/lib/types/boolean.ts
Expand Up @@ -6,15 +6,17 @@ export const boolean: ITypeHandler<boolean> = ( option: IFlagOptions, arg: IFlag
arg.optionalValue = true;
}

if ( value && ~[ '1', 'true' ].indexOf( value ) ) {
if ( !value ) {
return;
}

if ( ~[ '1', 'true' ].indexOf( value ) ) {
return true;
}

if ( value && ~[ '0', 'false' ].indexOf( value ) ) {
if ( ~[ '0', 'false' ].indexOf( value ) ) {
return false;
}

if ( value ) {
throw new Error( `Option --${ option.name } must be of type boolean but got: ${ value }` );
}
throw new Error( `Option --${ option.name } must be of type boolean but got: ${ value }` );
};

0 comments on commit 10997f6

Please sign in to comment.