Browse Source

Improve error handling in CLI and avoid defaulting to a generator on unknown option..

pull/1543/head
Joao Matos 5 years ago committed by João Matos
parent
commit
2b7ea694dd
  1. 17
      src/CLI/CLI.cs

17
src/CLI/CLI.cs

@ -227,7 +227,7 @@ namespace CppSharp
return; return;
} }
errorMessages.Add($"Unknown generator kind: {generator}. Defaulting to {options.Kind}"); errorMessages.Add($"Unknown generator kind: {generator}.");
} }
static void GetDestinationPlatform(string platform, List<string> errorMessages) static void GetDestinationPlatform(string platform, List<string> errorMessages)
@ -274,8 +274,6 @@ namespace CppSharp
List<string> errorMessages = new List<string>(); List<string> errorMessages = new List<string>();
bool helpShown = false; bool helpShown = false;
try
{
if (!ParseCommandLineArgs(args, errorMessages, ref helpShown)) if (!ParseCommandLineArgs(args, errorMessages, ref helpShown))
{ {
PrintErrorMessages(errorMessages); PrintErrorMessages(errorMessages);
@ -287,19 +285,12 @@ namespace CppSharp
Generator gen = new Generator(options); Generator gen = new Generator(options);
bool validOptions = gen.ValidateOptions(errorMessages); bool validOptions = gen.ValidateOptions(errorMessages);
PrintErrorMessages(errorMessages); PrintErrorMessages(errorMessages);
if (validOptions) if (errorMessages.Any() || !validOptions)
gen.Run(); Environment.Exit(1);
}
catch (Exception ex)
{
PrintErrorMessages(errorMessages);
Console.Error.WriteLine();
throw ex; gen.Run();
}
} }
} }
} }
Loading…
Cancel
Save