Refactored audiogen tool

This commit is contained in:
2023-02-13 17:07:24 -08:00
parent f1d13d2e45
commit 0794b8739c
21 changed files with 357 additions and 163 deletions

View File

@@ -17,9 +17,53 @@
using namespace Dawn;
std::vector<std::string> DawnTool::getRequiredFlags() {
return std::vector<std::string>();
}
std::map<std::string, std::string> DawnTool::getOptionalFlags() {
return std::map<std::string, std::string>();
}
int32_t DawnTool::exec(const int32_t argc, const char *argv[]) {
// Set up flags
flags = this->getOptionalFlags();
// Parse args
for(int32_t i = 0; i < argc; i++) {
this->args.push_back(std::string(argv[i]));
std::string a(argv[i]);
this->args.push_back(a);
// First arg is the path, we ignore it.
if(i == 0) continue;
// Is this a flag-like arg, as in has "--[name]=[value]"
if(a.size() < 5) continue;
if(a[0] != '-' || a[1] != '-') continue;
// Remove --
auto flag = a.erase(0, 2);
// Ensure = is present
auto equalPos = flag.find('=');
if(equalPos == std::string::npos) continue;
// Get prefix and val and store
auto prefix = flag.substr(0, equalPos);
auto val = flag.substr(equalPos + 1);
flags[prefix] = val;
}
// Now validate flags
auto required = this->getRequiredFlags();
auto itReq = required.begin();
while(itReq != required.end()) {
auto match = flags.find(*itReq);
if(match == flags.end()) {
std::cout << "Missing required flag \"" + *itReq + "\"!" << std::endl;
return 1;
}
++itReq;
}
return this->start();