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