Do not validate values for options without value

This commit is contained in:
LordGrey 2023-10-23 21:08:05 +02:00
parent a5625cf984
commit 7aa1cd87ea

View File

@ -14,19 +14,22 @@ bool Parser::parse(const QStringList &arguments)
return false; return false;
} }
for(Option * option : _options) for(Option * option : std::as_const(_options))
{ {
QString value = this->value(*option); if (!option->valueName().isEmpty())
if (!option->validate(*this, value)) { {
const QString error = option->getError(); QString value = this->value(*option);
if (!error.isEmpty()) { if (!option->validate(*this, value)) {
_errorText = tr("\"%1\" is not a valid option for %2, %3").arg(value, option->name(), error); const QString error = option->getError();
if (!error.isEmpty()) {
_errorText = tr("\"%1\" is not a valid option for %2, %3").arg(value, option->name(), error);
}
else
{
_errorText = tr("\"%1\" is not a valid option for %2").arg(value, option->name());
}
return false;
} }
else
{
_errorText = tr("\"%1\" is not a valid option for %2").arg(value, option->name());
}
return false;
} }
} }
return true; return true;