| 74 | } |
| 75 | |
| 76 | int main(int argc, char *argv[]) { |
| 77 | namespace po = boost::program_options; |
| 78 | std::string inFilename; |
| 79 | // clang-format off |
| 80 | po::options_description desc("Options"); |
| 81 | desc.add_options() |
| 82 | ("help", "produce help message") |
| 83 | ("symbol,S", po::value<std::string>()->default_value("json"), "symbol/variable name to create in generated file") |
| 84 | ("output,O", po::value<std::string>(), "output file (defaults to standard out)") |
| 85 | ; |
| 86 | po::options_description hidden("Hidden (positional-only) options"); |
| 87 | hidden.add_options() |
| 88 | ("input", po::value<std::string>(&inFilename)) |
| 89 | ; |
| 90 | // clang-format on |
| 91 | |
| 92 | po::positional_options_description p; |
| 93 | p.add("input", 1); |
| 94 | p.add("output", 1); |
| 95 | |
| 96 | po::variables_map vm; |
| 97 | po::store(po::command_line_parser(argc, argv) |
| 98 | .options(po::options_description().add(desc).add(hidden)) |
| 99 | .positional(p) |
| 100 | .run(), |
| 101 | vm); |
| 102 | po::notify(vm); |
| 103 | if (vm.count("help") || (vm.count("input") == 0)) { |
| 104 | std::cout << "Usage: osvr_json_to_cpp <input> [output]\n"; |
| 105 | std::cout << desc << "\n"; |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | std::ifstream inFile(inFilename.c_str()); |
| 110 | try { |
| 111 | if (vm.count("output")) { |
| 112 | std::ofstream outFile(vm["output"].as<std::string>().c_str()); |
| 113 | convertJsonToLiteral(vm["symbol"].as<std::string>(), inFile, |
| 114 | outFile); |
| 115 | } else { |
| 116 | convertJsonToLiteral(vm["symbol"].as<std::string>(), inFile, |
| 117 | std::cout); |
| 118 | } |
| 119 | } catch (std::exception &e) { |
| 120 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 121 | return 1; |
| 122 | } |
| 123 | return 0; |
| 124 | } |
nothing calls this directly
no test coverage detected