| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 library servicec_blaze; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'dart:io'; | |
| 10 | |
| 11 import 'package:servicec/compiler.dart' show | |
| 12 compile; | |
| 13 | |
| 14 import 'package:servicec/errors.dart' show | |
| 15 CompilationError, | |
| 16 ErrorReporter; | |
| 17 | |
| 18 class ServicecRunner { | |
| 19 | |
| 20 Future<int> run(List<String> arguments) async { | |
| 21 String idl = null; | |
| 22 String out = null; | |
| 23 String resources = null; | |
| 24 | |
| 25 for (int i = 0; i < arguments.length; ++i) { | |
| 26 String arg = arguments[i]; | |
| 27 if (arg == "--out") { | |
| 28 if (out != null) throw "Cannot supply multiple output directories"; | |
| 29 out = arguments[++i]; | |
| 30 } else if (arg == "--resources") { | |
| 31 if (resources != null) { | |
| 32 throw "Cannot supply multiple resource directories"; | |
| 33 } | |
| 34 resources = arguments[++i]; | |
| 35 } else if (arg.startsWith("-")) { | |
| 36 throw "Unknown option $arg"; | |
| 37 } else { | |
| 38 if (idl != null) throw "Cannot compile multiple IDL files"; | |
| 39 idl = arg; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 if (idl == null) { | |
| 44 throw "Supply an IDL file to compile"; | |
| 45 } | |
| 46 if (out == null) { | |
| 47 throw "Supply an output directory with " | |
| 48 + "--out <path to output directory>"; | |
| 49 } | |
| 50 if (resources == null) { | |
| 51 throw "Supply the servicec resources root with " | |
| 52 + "--resources <path to resources root>"; | |
| 53 } | |
| 54 | |
| 55 Iterable<CompilationError> errors = await compile(idl, resources, out); | |
| 56 | |
| 57 if (errors.isNotEmpty) { | |
| 58 print("Encountered errors while compiling definitions in $idl."); | |
| 59 new ErrorReporter(idl, idl).report(errors); | |
| 60 return 1; | |
| 61 } | |
| 62 | |
| 63 return 0; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 main(List<String> arguments) async { | |
| 68 return await new ServicecRunner().run(arguments); | |
| 69 } | |
| OLD | NEW |