Browse Source

Improve option checking.

pull/12/merge
triton 13 years ago
parent
commit
16bd9d1deb
  1. 22
      src/Generator/Driver.cs

22
src/Generator/Driver.cs

@ -44,11 +44,11 @@ namespace CppSharp
static void ValidateOptions(DriverOptions options) static void ValidateOptions(DriverOptions options)
{ {
if (string.IsNullOrWhiteSpace(options.LibraryName)) if (!Generators.ContainsKey(options.GeneratorKind))
throw new InvalidDataException(); throw new InvalidOptionException();
if (options.OutputDir == null) if (string.IsNullOrWhiteSpace(options.LibraryName))
options.OutputDir = Directory.GetCurrentDirectory(); throw new InvalidOptionException();
for (var i = 0; i < options.IncludeDirs.Count; i++) for (var i = 0; i < options.IncludeDirs.Count; i++)
{ {
@ -68,12 +68,6 @@ namespace CppSharp
{ {
ValidateOptions(Options); ValidateOptions(Options);
if (!Directory.Exists(Options.OutputDir))
Directory.CreateDirectory(Options.OutputDir);
if (!Generators.ContainsKey(Options.GeneratorKind))
throw new NotImplementedException("Unknown generator kind");
Generator = Generators[Options.GeneratorKind](this); Generator = Generators[Options.GeneratorKind](this);
} }
@ -232,6 +226,14 @@ namespace CppSharp
public Func<TranslationUnit, string> GenerateName; public Func<TranslationUnit, string> GenerateName;
} }
public class InvalidOptionException : Exception
{
public InvalidOptionException()
{
}
}
public static class ConsoleDriver public static class ConsoleDriver
{ {
static void OnFileParsed(string file, ParserResult result) static void OnFileParsed(string file, ParserResult result)

Loading…
Cancel
Save