@@ -101,7 +101,8 @@ static async Task<int> Main(string[] args)
101101 var packageName = context . ParseResult . GetValueForOption ( packageNameOption ) ;
102102 var packageVersion = context . ParseResult . GetValueForOption ( packageVersionOption ) ;
103103
104- await Generate ( input , output , format , namespaces , raw , singleFile , strict , exports , package_ , packageName , packageVersion ) ;
104+ var exitCode = await Generate ( input , output , format , namespaces , raw , singleFile , strict , exports , package_ , packageName , packageVersion ) ;
105+ context . ExitCode = exitCode ;
105106 } ) ;
106107
107108 // Validate command
@@ -120,18 +121,22 @@ static async Task<int> Main(string[] args)
120121 validateCommand . AddOption ( validateInputOption ) ;
121122 validateCommand . AddOption ( validateStrictOption ) ;
122123
123- validateCommand . SetHandler ( async ( input , strict ) =>
124+ validateCommand . SetHandler ( async ( context ) =>
124125 {
125- await Validate ( input , strict ) ;
126- } , validateInputOption , validateStrictOption ) ;
126+ var input = context . ParseResult . GetValueForOption ( validateInputOption ) ! ;
127+ var strict = context . ParseResult . GetValueForOption ( validateStrictOption ) ;
128+
129+ var exitCode = await Validate ( input , strict ) ;
130+ context . ExitCode = exitCode ;
131+ } ) ;
127132
128133 rootCommand . AddCommand ( generateCommand ) ;
129134 rootCommand . AddCommand ( validateCommand ) ;
130135
131136 return await rootCommand . InvokeAsync ( args ) ;
132137 }
133138
134- static async Task Generate ( string input , string output , string format , string [ ] ? namespaces , bool raw , bool singleFile , bool strict , bool exports , bool package_ , string ? packageName , string ? packageVersion )
139+ static async Task < int > Generate ( string input , string output , string format , string [ ] ? namespaces , bool raw , bool singleFile , bool strict , bool exports , bool package_ , string ? packageName , string ? packageVersion )
135140 {
136141 Console . WriteLine ( $ "Generating { format } output...") ;
137142 Console . WriteLine ( $ "Input: { input } ") ;
@@ -140,24 +145,21 @@ static async Task Generate(string input, string output, string format, string[]?
140145 if ( singleFile && ! raw )
141146 {
142147 Console . Error . WriteLine ( "Error: --single-file requires --raw" ) ;
143- Environment . ExitCode = 1 ;
144- return ;
148+ return 1 ;
145149 }
146150
147151 if ( exports && ( ! raw || ! singleFile ) )
148152 {
149153 Console . Error . WriteLine ( "Error: --exports requires --raw --single-file" ) ;
150- Environment . ExitCode = 1 ;
151- return ;
154+ return 1 ;
152155 }
153156
154157 if ( package_ )
155158 {
156159 if ( string . IsNullOrEmpty ( packageName ) )
157160 {
158161 Console . Error . WriteLine ( "Error: --package requires --package-name" ) ;
159- Environment . ExitCode = 1 ;
160- return ;
162+ return 1 ;
161163 }
162164
163165 // If raw mode is specified with package, also enable single-file and exports
@@ -177,8 +179,7 @@ static async Task Generate(string input, string output, string format, string[]?
177179 {
178180 Console . WriteLine ( $ "\n Generation aborted due to { errors . Count } errors" +
179181 ( strict && warnings . Count > 0 ? $ " and { warnings . Count } warnings (--strict)" : "" ) ) ;
180- Environment . ExitCode = 1 ;
181- return ;
182+ return 1 ;
182183 }
183184
184185 // Create exporter based on format
@@ -195,8 +196,7 @@ static async Task Generate(string input, string output, string format, string[]?
195196 if ( exporter == null )
196197 {
197198 Console . Error . WriteLine ( $ "Error: Unknown format '{ format } '. Supported formats: typescript, lua, csharp, json, proto") ;
198- Environment . ExitCode = 1 ;
199- return ;
199+ return 1 ;
200200 }
201201
202202 var options = new ExportOptions
@@ -218,9 +218,10 @@ static async Task Generate(string input, string output, string format, string[]?
218218 Console . WriteLine ( $ "\n Generated { db . Namespaces . Sum ( n => n . Natives . Count ) } natives in { db . Namespaces . Count } namespaces") ;
219219 Console . WriteLine ( $ "Included { db . Enums . Count } enums and { db . Structs . Count } structs") ;
220220 Console . WriteLine ( $ "Output written to: { output } ") ;
221+ return 0 ;
221222 }
222223
223- static async Task Validate ( string input , bool strict )
224+ static async Task < int > Validate ( string input , bool strict )
224225 {
225226 Console . WriteLine ( $ "Validating MDX files in: { input } ") ;
226227
@@ -236,10 +237,7 @@ static async Task Validate(string input, bool strict)
236237 Console . WriteLine ( $ "Validated { totalFiles } files in { db . Namespaces . Count } namespaces") ;
237238 Console . WriteLine ( $ "Found { errors . Count } errors, { warnings . Count } warnings") ;
238239
239- if ( errorCount > 0 )
240- {
241- Environment . ExitCode = 1 ;
242- }
240+ return errorCount > 0 ? 1 : 0 ;
243241 }
244242
245243 static async Task < ( NativeCodeGen . Core . Parsing . NativeDatabase db , List < ParseError > errors , List < ParseWarning > warnings ) > ParseAllFiles ( string inputDir )
0 commit comments