@@ -37,7 +37,7 @@ export interface IntegerFlagOptions extends BaseFlagOptions {
3737
3838export type TaggedFlagBuilder < Tag extends FlagTag , ChoicesType = unknown , Required = boolean , HasDefault = false > = {
3939 flagTag : Tag ;
40- builder : ( args : Argv , objectName : string , extraArgs ?: string [ ] ) => Argv ;
40+ builder : ( args : Argv , objectName : string , extraArgs ?: string [ ] , invertDefaultIfSet ?: boolean ) => Argv ;
4141 choicesType : ChoicesType ;
4242 required : Required ;
4343 hasDefault : HasDefault ;
@@ -62,7 +62,7 @@ function stringFlag<const Choices, const T extends StringFlagOptions<readonly st
6262) : TaggedFlagBuilder < 'string' , Choices , T [ 'default' ] extends string ? true : T [ 'required' ] , T [ 'default' ] > {
6363 return {
6464 flagTag : 'string' ,
65- builder : ( args , objectName , extraAliases ) => {
65+ builder : ( args , objectName , extraAliases , invertDefaultIfSet = false ) => {
6666 const allAliases = new Set ( [ ...( options . aliases ?? [ ] ) , ...( extraAliases ?? [ ] ) ] ) ;
6767
6868 if ( options . char ) {
@@ -77,7 +77,7 @@ function stringFlag<const Choices, const T extends StringFlagOptions<readonly st
7777 alias : [ ...allAliases ] . map ( ( alias ) => kebabCaseString ( camelCaseToKebabCase ( alias ) ) ) ,
7878 hidden : options . hidden ?? false ,
7979 conflicts : options . exclusive ,
80- default : options . default ,
80+ default : invertDefaultIfSet ? ! options . default : options . default ,
8181 choices : options . choices ,
8282 string : true ,
8383 // we only require something be passed in if we don't have a default or read from stdin
@@ -102,7 +102,7 @@ function booleanFlag<const T extends BooleanFlagOptions>(
102102) : TaggedFlagBuilder < 'boolean' , never , T [ 'default' ] extends boolean ? true : T [ 'required' ] , T [ 'default' ] > {
103103 return {
104104 flagTag : 'boolean' ,
105- builder : ( args , objectName , extraAliases ) => {
105+ builder : ( args , objectName , extraAliases , invertDefaultIfSet = false ) => {
106106 const allAliases = new Set ( [ ...( options . aliases ?? [ ] ) , ...( extraAliases ?? [ ] ) ] ) ;
107107
108108 if ( options . char ) {
@@ -117,7 +117,7 @@ function booleanFlag<const T extends BooleanFlagOptions>(
117117 alias : [ ...allAliases ] . map ( ( alias ) => kebabCaseString ( camelCaseToKebabCase ( alias ) ) ) ,
118118 hidden : options . hidden ?? false ,
119119 conflicts : options . exclusive ,
120- default : options . default ,
120+ default : invertDefaultIfSet ? ! options . default : options . default ,
121121 boolean : true ,
122122 } ) ;
123123 } ,
@@ -139,7 +139,7 @@ function integerFlag<const T extends IntegerFlagOptions>(
139139) : TaggedFlagBuilder < 'integer' , never , T [ 'default' ] extends number ? true : T [ 'required' ] , T [ 'default' ] > {
140140 return {
141141 flagTag : 'integer' ,
142- builder : ( args , objectName , extraAliases ) => {
142+ builder : ( args , objectName , extraAliases , invertDefaultIfSet = false ) => {
143143 const allAliases = new Set ( [ ...( options . aliases ?? [ ] ) , ...( extraAliases ?? [ ] ) ] ) ;
144144
145145 if ( options . char ) {
@@ -154,7 +154,7 @@ function integerFlag<const T extends IntegerFlagOptions>(
154154 alias : [ ...allAliases ] . map ( ( alias ) => kebabCaseString ( camelCaseToKebabCase ( alias ) ) ) ,
155155 hidden : options . hidden ?? false ,
156156 conflicts : options . exclusive ,
157- default : options . default ,
157+ default : invertDefaultIfSet ? ! options . default : options . default ,
158158 choices : options . choices ,
159159 string : true ,
160160 nargs : 1 ,
0 commit comments