Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using Google.ProtocolBuffers.DescriptorProtos;
  4. namespace Google.ProtocolBuffers.ProtoGen {
  5. /// <summary>
  6. /// Entry point for the Protocol Buffers generator.
  7. /// </summary>
  8. class Program {
  9. static int Main(string[] args) {
  10. try {
  11. // Hack to make sure everything's initialized
  12. DescriptorProtoFile.Descriptor.ToString();
  13. GeneratorOptions options = ParseCommandLineArguments(args);
  14. IList<string> validationFailures;
  15. if (!options.TryValidate(out validationFailures)) {
  16. // We've already got the message-building logic in the exception...
  17. InvalidOptionsException exception = new InvalidOptionsException(validationFailures);
  18. Console.WriteLine(exception.Message);
  19. return 1;
  20. }
  21. Generator generator = Generator.CreateGenerator(options);
  22. generator.Generate();
  23. return 0;
  24. } catch (Exception e) {
  25. Console.Error.WriteLine("Error: {0}", e.Message);
  26. Console.Error.WriteLine();
  27. Console.Error.WriteLine("Detailed exception information: {0}", e);
  28. return 1;
  29. }
  30. }
  31. private static GeneratorOptions ParseCommandLineArguments(string[] args) {
  32. GeneratorOptions options = new GeneratorOptions();
  33. //string baseDir = "c:\\Users\\Jon\\Documents\\Visual Studio 2008\\Projects\\ProtocolBuffers";
  34. //options.OutputDirectory = baseDir + "\\tmp";
  35. //options.InputFiles = new[] { baseDir + "\\protos\\nwind-solo.protobin" };
  36. options.OutputDirectory = ".";
  37. options.InputFiles = args;
  38. return options;
  39. }
  40. }
  41. }