| 48 | using codegen::util::WriteToFile; |
| 49 | |
| 50 | int |
| 51 | main(int argc, char const** argv, char**) |
| 52 | { |
| 53 | int returnCode = 0; |
| 54 | int const FailureReturnCode = -1; |
| 55 | |
| 56 | std::vector<std::string> args(argv, argv + argc); |
| 57 | |
| 58 | // Validate program options ordering. |
| 59 | // Return the iterator corresponding to the option argument. |
| 60 | // Error conditions: |
| 61 | // 1. the option doesn't exist |
| 62 | // 2. the option argument doesn't exist |
| 63 | // 3. the option argument starts with a '-' |
| 64 | auto findOrThrow = [&args](std::string const& key) |
| 65 | { |
| 66 | auto it = std::find(std::begin(args), std::end(args), key); |
| 67 | if (it == args.end()) |
| 68 | { |
| 69 | throw std::runtime_error("Cannot find option " + key); |
| 70 | } |
| 71 | ++it; |
| 72 | if (it == args.end()) |
| 73 | { |
| 74 | throw std::runtime_error("No argument provided for option " + key); |
| 75 | } |
| 76 | if (it->at(0) == '-') |
| 77 | { |
| 78 | throw std::runtime_error("The argument " + key + " cannot be an option i.e. it cannot start with -"); |
| 79 | } |
| 80 | return it; |
| 81 | }; |
| 82 | |
| 83 | // Validate if file stream is open. Otherwise, throw |
| 84 | auto checkFileOpenOrThrow = [](auto const& fstream) |
| 85 | { |
| 86 | if (!fstream.is_open()) |
| 87 | { |
| 88 | throw std::runtime_error("Failed to open manifest file"); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | try |
| 93 | { |
| 94 | auto it = findOrThrow("--manifest"); |
| 95 | std::string manifestFilePath = *it; |
| 96 | it = findOrThrow("--out-file"); |
| 97 | std::string outFilePath = *it; |
| 98 | // --include-headers is followed by 1 or more header strings. Parse until the end of |
| 99 | // vector or until the next occurence of '-' |
| 100 | std::vector<std::string> includeHeaderPaths; |
| 101 | for (it = findOrThrow("--include-headers"); it != args.end() && !(it->at(0) == '-'); ++it) |
| 102 | { |
| 103 | includeHeaderPaths.push_back(*it); |
| 104 | } |
| 105 | |
| 106 | std::ifstream manifestFile(manifestFilePath, std::ifstream::binary | std::ifstream::in); |
| 107 | checkFileOpenOrThrow(manifestFile); |
nothing calls this directly
no test coverage detected