minor refactor

This commit is contained in:
MihailRis
2024-05-17 15:46:54 +03:00
parent 2a8b750ad7
commit 8ff629e1cd
15 changed files with 120 additions and 107 deletions
+35
View File
@@ -1,9 +1,44 @@
#include "command_line.hpp"
#include "../files/engine_paths.hpp"
#include <iostream>
#include <filesystem>
#include <string>
#include <cstring>
#include <stdexcept>
namespace fs = std::filesystem;
class ArgsReader {
int argc;
char** argv;
int pos = 0;
const char* last = "";
public:
ArgsReader(int argc, char** argv) : argc(argc), argv(argv) {}
void skip() {
pos++;
}
bool hasNext() const {
return pos < argc && strlen(argv[pos]);
}
bool isKeywordArg() const {
return last[0] == '-';
}
std::string next() {
if (pos >= argc) {
throw std::runtime_error("unexpected end");
}
last = argv[pos];
return argv[pos++];
}
};
bool perform_keyword(ArgsReader& reader, const std::string& keyword, EnginePaths& paths) {
if (keyword == "--res") {
auto token = reader.next();