Skip to content

Commit 2b7ea69

Browse files
committed
Improve error handling in CLI and avoid defaulting to a generator on unknown option..
1 parent 6ea853e commit 2b7ea69

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/CLI/CLI.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static void GetGeneratorKind(string generator, List<string> errorMessages)
227227
return;
228228
}
229229

230-
errorMessages.Add($"Unknown generator kind: {generator}. Defaulting to {options.Kind}");
230+
errorMessages.Add($"Unknown generator kind: {generator}.");
231231
}
232232

233233
static void GetDestinationPlatform(string platform, List<string> errorMessages)
@@ -274,8 +274,6 @@ static void Main(string[] args)
274274
List<string> errorMessages = new List<string>();
275275
bool helpShown = false;
276276

277-
try
278-
{
279277
if (!ParseCommandLineArgs(args, errorMessages, ref helpShown))
280278
{
281279
PrintErrorMessages(errorMessages);
@@ -287,19 +285,12 @@ static void Main(string[] args)
287285
Generator gen = new Generator(options);
288286

289287
bool validOptions = gen.ValidateOptions(errorMessages);
290-
291288
PrintErrorMessages(errorMessages);
292289

293-
if (validOptions)
294-
gen.Run();
295-
}
296-
catch (Exception ex)
297-
{
298-
PrintErrorMessages(errorMessages);
299-
Console.Error.WriteLine();
290+
if (errorMessages.Any() || !validOptions)
291+
Environment.Exit(1);
300292

301-
throw ex;
302-
}
293+
gen.Run();
303294
}
304295
}
305296
}

0 commit comments

Comments
 (0)