Util+Test: Add setting to stop parsing on first non-option

This commit is contained in:
Riyyi
2021-09-06 20:37:39 +02:00
parent a70d67f8fa
commit f92b75a463
3 changed files with 71 additions and 11 deletions
+7 -3
View File
@@ -24,7 +24,7 @@ void ArgParser::printOptionError(char name, Error error)
void ArgParser::printOptionError(const char* name, Error error, bool longName)
{
if (!m_errorMessages) {
if (!m_errorReporting) {
return;
}
@@ -206,14 +206,15 @@ bool ArgParser::parse(int argc, const char* argv[])
{
bool result = true;
// Skip program name argument
m_optionIndex = 1;
// By default parse all '-' prefixed parameters as options
m_nonOptionMode = false;
// Get program name
m_name = argv[0] + std::string_view(argv[0]).find_last_of('/') + 1;
printf("name: %s\n", m_name);
std::string_view argument;
std::string_view next;
for (; m_optionIndex < argc; ++m_optionIndex) {
@@ -250,6 +251,9 @@ bool ArgParser::parse(int argc, const char* argv[])
}
// Argument
else {
if (m_stopParsingOnFirstNonOption) {
m_nonOptionMode = true;
}
printf("-> argu: '%s'", argument.data());
}
}