Move cmdLineArgs lib to external

This commit is contained in:
2022-11-13 19:52:19 +01:00
parent 91d3952ea0
commit 2da39359c6
7 changed files with 69 additions and 21 deletions

71
external/cmdLineArgs/cmdLineArgs.cpp vendored Normal file
View File

@@ -0,0 +1,71 @@
#include "cmdLineArgs.hpp"
cmdLineArgs_c::cmdLineArgs_c(int argc, char *argv[])
{
for (int i = 0; i < argc; i++)
{
this->args.push_back(argv[i]);
}
}
std::string cmdLineArgs_c::get_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
if (it + 1 != end)
return *(it + 1);
}
return "";
}
bool cmdLineArgs_c::has_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
return false;
}
void cmdLineArgs_c::setUsage(std::string usage)
{
this->usage = usage;
}
std::string cmdLineArgs_c::getUsage()
{
return this->usage;
}
bool cmdLineArgs_c::available(
const std::string &option_name,
const std::string usage
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << " " << usage);
return false;
}
bool cmdLineArgs_c::available(
const std::string &option_name
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << std::endl << "\t" << this->usage);
return false;
}