| 124 | } |
| 125 | |
| 126 | int main(int argc, char *argv[]) { |
| 127 | Args args = parseArguments(argc, argv); |
| 128 | |
| 129 | if (MapContainsKey(args.flags, "version")) { |
| 130 | #ifdef ESMB_VERSION |
| 131 | std::cout << ESMB_VERSION << std::endl; |
| 132 | #else |
| 133 | std::cout << esmb_media_version() << std::endl; |
| 134 | #endif |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | if (MapContainsKey(args.flags, "help")) { |
| 139 | std::cout << printHelp(); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | if (args.args.size() < 3) { |
| 144 | std::cerr << printHelp(); |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | std::string function = args.args[1]; |
| 149 | bool isInputFunc = MapContainsKey(esmb::Image::FunctionMap, function); |
| 150 | bool isNoInputFunc = MapContainsKey(esmb::Image::NoInputFunctionMap, function); |
| 151 | if ((!isInputFunc && !isNoInputFunc) || (isInputFunc && args.args.size() < 4)) { |
| 152 | std::cerr << printHelp(); |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | if (!MapContainsKey(args.flags, "basePath")) { |
| 157 | args.flags["basePath"] = std::filesystem::current_path().string() + "/"; |
| 158 | } |
| 159 | |
| 160 | if (MapContainsKey(esmb::Image::FunctionArgsMap, function)) { |
| 161 | FunctionArgs *funcArgs = esmb::Image::FunctionArgsMap.at(function); |
| 162 | for (auto arg : *funcArgs) { |
| 163 | if (!MapContainsKey(args.flags, arg.first)) { |
| 164 | if (arg.second.required) { |
| 165 | std::cerr << "Missing required arguments. The following arguments are required for this function: "; |
| 166 | bool started = false; |
| 167 | for (auto arg : *funcArgs) { |
| 168 | if (arg.second.required && arg.first != "basePath") { |
| 169 | if (started) { |
| 170 | std::cerr << ", "; |
| 171 | } |
| 172 | std::cerr << "--" << arg.first; |
| 173 | started = true; |
| 174 | } |
| 175 | } |
| 176 | std::cerr << std::endl; |
| 177 | return 1; |
| 178 | } |
| 179 | continue; |
| 180 | } |
| 181 | |
| 182 | // only check for strings for now, the parser *should* handle bools properly? |
| 183 | std::string val = GetArgument<std::string>(args.flags, arg.first); |
nothing calls this directly
no test coverage detected