@@ -10,6 +10,10 @@ type ParseResult<T> =
1010 { isValid : true ; result : T }
1111 | { isValid : false , errorMessage : string } ;
1212
13+ type ArgumentParseResult < T > =
14+ { isValid : true ; result : T ; increment ?: number }
15+ | { isValid : false , errorMessage : string } ;
16+
1317interface ParsedCommandLine extends ts . ParsedCommandLine {
1418 options : CompilerOptions ;
1519}
@@ -190,10 +194,11 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
190194 const argumentName = args [ i ] . substr ( 2 ) ;
191195 const option = optionDeclarations [ argumentName ] ;
192196 if ( option ) {
193- const argumentResult = getArgumentValue ( argumentName , args [ i + 1 ] ) ;
194- i ++ ; // Skip the value from being considered as argument name
197+ const argumentResult = getArgumentValue ( argumentName , i , args ) ;
195198 if ( argumentResult . isValid === true ) {
196199 result [ argumentName ] = argumentResult . result ;
200+ // Skip value from being considered as option
201+ i += argumentResult . increment !== undefined ? argumentResult . increment : 1 ;
197202 } else {
198203 return { isValid : false , errorMessage : argumentResult . errorMessage } ;
199204 }
@@ -209,10 +214,11 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
209214 }
210215
211216 if ( argumentName ) {
212- const argumentResult = getArgumentValue ( argumentName , args [ i + 1 ] ) ;
213- i ++ ; // Skip the value from being considered as argument name
217+ const argumentResult = getArgumentValue ( argumentName , i , args ) ;
214218 if ( argumentResult . isValid === true ) {
215219 result [ argumentName ] = argumentResult . result ;
220+ // Skip value from being considered as option
221+ i += argumentResult . increment !== undefined ? argumentResult . increment : 1 ;
216222 } else {
217223 return { isValid : false , errorMessage : argumentResult . errorMessage } ;
218224 }
@@ -232,13 +238,24 @@ function parseTSTLOptions(commandLine: ts.ParsedCommandLine, args: string[]): CL
232238 return { isValid : true , result : commandLine } ;
233239}
234240
235- function getArgumentValue ( argumentName : string , argument : string ) : ParseResult < string | boolean >
241+ function getArgumentValue (
242+ argumentName : string ,
243+ argumentIndex : number ,
244+ args : string [ ]
245+ ) : ArgumentParseResult < string | boolean >
236246{
247+ const option = optionDeclarations [ argumentName ] ;
248+ const argument = args [ argumentIndex + 1 ] ;
249+
250+ if ( option . type === "boolean" && ( argument === undefined || argument . startsWith ( "-" ) ) ) {
251+ // Set boolean arguments without supplied value to true
252+ return { isValid : true , result : true , increment : 0 } ;
253+ }
254+
237255 if ( argument === undefined ) {
238256 return { isValid : false , errorMessage : `Missing value for parameter ${ argumentName } ` } ;
239257 }
240258
241- const option = optionDeclarations [ argumentName ] ;
242259 const value = readValue ( argument , option . type , argumentName ) ;
243260
244261 if ( option . choices ) {
0 commit comments