Added ArgsParser class.

This commit is contained in:
2025-01-27 00:53:08 -05:00
parent e2e26a484b
commit 24e7474769
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#pragma once
#include <vector>
#include <string>
#include <Core/Macros.hpp>
class ArgsParser
{
public:
ArgsParser(int argc, char** argv);
explicit ArgsParser(std::vector<std::string> argv);
explicit ArgsParser(const std::string& args_str);
explicit ArgsParser(const std::string& exec, const std::vector<std::string>& tok);
bool FlagPresent(const std::string& flag) const;
std::vector<std::string> GetFlags() const {
}
std::string executable;
std::string full_args;
std::vector<std::string> tokens;
};

View File

@@ -0,0 +1,31 @@
#include <Core/ArgsParser.hpp>
ArgsParser::ArgsParser(int argc, char **argv) {
executable = std::string(argv[0]);
tokens = std::vector<std::string>(argv + 1, argv + argc);
for (auto& token : tokens)
full_args.append(std::string(token).append(" "));
}
ArgsParser::ArgsParser(std::vector<std::string> argv) {
executable = argv[0];
full_args = string_build(argv);
tokens = {argv.begin() + 1, argv.end()};
}
ArgsParser::ArgsParser(const std::string &args_str) {
full_args = args_str;
std::vector<std::string> temp_tokens = string_split(full_args, ' ');
tokens = {temp_tokens.begin() + 1, temp_tokens.end()};
}
ArgsParser::ArgsParser(const std::string &exec, const std::vector<std::string> &tok) {
executable = exec;
tokens = tok;
for (auto& token : tokens)
full_args.append(std::string(token).append(" "));
}
bool ArgsParser::FlagPresent(const std::string &flag) const {
return std::ranges::find(tokens, flag) != tokens.end();
}