Reduce indentation in argumentparser.cpp
This commit is contained in:
parent
04a8ef02d5
commit
80fba8b6d4
|
@ -620,11 +620,12 @@ void Argument::setSubArguments(const ArgumentInitializerList &secondaryArguments
|
||||||
*/
|
*/
|
||||||
void Argument::addSubArgument(Argument *arg)
|
void Argument::addSubArgument(Argument *arg)
|
||||||
{
|
{
|
||||||
if (find(m_subArgs.cbegin(), m_subArgs.cend(), arg) == m_subArgs.cend()) {
|
if (find(m_subArgs.cbegin(), m_subArgs.cend(), arg) != m_subArgs.cend()) {
|
||||||
m_subArgs.push_back(arg);
|
return;
|
||||||
if (find(arg->m_parents.cbegin(), arg->m_parents.cend(), this) == arg->m_parents.cend()) {
|
}
|
||||||
arg->m_parents.push_back(this);
|
m_subArgs.push_back(arg);
|
||||||
}
|
if (find(arg->m_parents.cbegin(), arg->m_parents.cend(), this) == arg->m_parents.cend()) {
|
||||||
|
arg->m_parents.push_back(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,12 +669,13 @@ Argument *Argument::conflictsWithArgument() const
|
||||||
*/
|
*/
|
||||||
Argument *Argument::wouldConflictWithArgument() const
|
Argument *Argument::wouldConflictWithArgument() const
|
||||||
{
|
{
|
||||||
if (!isCombinable()) {
|
if (isCombinable()) {
|
||||||
for (Argument *parent : m_parents) {
|
return nullptr;
|
||||||
for (Argument *sibling : parent->subArguments()) {
|
}
|
||||||
if (sibling != this && sibling->isPresent() && !sibling->isCombinable()) {
|
for (Argument *parent : m_parents) {
|
||||||
return sibling;
|
for (Argument *sibling : parent->subArguments()) {
|
||||||
}
|
if (sibling != this && sibling->isPresent() && !sibling->isCombinable()) {
|
||||||
|
return sibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,28 +744,26 @@ ArgumentParser::ArgumentParser()
|
||||||
*/
|
*/
|
||||||
void ArgumentParser::setMainArguments(const ArgumentInitializerList &mainArguments)
|
void ArgumentParser::setMainArguments(const ArgumentInitializerList &mainArguments)
|
||||||
{
|
{
|
||||||
if (mainArguments.size()) {
|
if (!mainArguments.size()) {
|
||||||
for (Argument *arg : mainArguments) {
|
|
||||||
arg->m_isMainArg = true;
|
|
||||||
}
|
|
||||||
m_mainArgs.assign(mainArguments);
|
|
||||||
if (!m_defaultArg) {
|
|
||||||
if (!(*mainArguments.begin())->requiredValueCount()) {
|
|
||||||
bool subArgsRequired = false;
|
|
||||||
for (const Argument *subArg : (*mainArguments.begin())->subArguments()) {
|
|
||||||
if (subArg->isRequired()) {
|
|
||||||
subArgsRequired = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!subArgsRequired) {
|
|
||||||
m_defaultArg = *mainArguments.begin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_mainArgs.clear();
|
m_mainArgs.clear();
|
||||||
}
|
}
|
||||||
|
for (Argument *arg : mainArguments) {
|
||||||
|
arg->m_isMainArg = true;
|
||||||
|
}
|
||||||
|
m_mainArgs.assign(mainArguments);
|
||||||
|
if (m_defaultArg || (*mainArguments.begin())->requiredValueCount()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool subArgsRequired = false;
|
||||||
|
for (const Argument *subArg : (*mainArguments.begin())->subArguments()) {
|
||||||
|
if (subArg->isRequired()) {
|
||||||
|
subArgsRequired = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!subArgsRequired) {
|
||||||
|
m_defaultArg = *mainArguments.begin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1587,25 +1587,26 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args)
|
||||||
throw Failure(argsToString("The argument \"", conflictingArgument->name(), "\" can not be combined with \"", arg->name(), "\"."));
|
throw Failure(argsToString("The argument \"", conflictingArgument->name(), "\" can not be combined with \"", arg->name(), "\"."));
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i != occurrences; ++i) {
|
for (size_t i = 0; i != occurrences; ++i) {
|
||||||
if (!arg->allRequiredValuesPresent(i)) {
|
if (arg->allRequiredValuesPresent(i)) {
|
||||||
stringstream ss(stringstream::in | stringstream::out);
|
continue;
|
||||||
ss << "Not all parameter for argument \"" << arg->name() << "\" ";
|
|
||||||
if (i) {
|
|
||||||
ss << " (" << (i + 1) << " occurrence) ";
|
|
||||||
}
|
|
||||||
ss << "provided. You have to provide the following parameter:";
|
|
||||||
size_t valueNamesPrint = 0;
|
|
||||||
for (const auto &name : arg->m_valueNames) {
|
|
||||||
ss << ' ' << name;
|
|
||||||
++valueNamesPrint;
|
|
||||||
}
|
|
||||||
if (arg->m_requiredValueCount != Argument::varValueCount) {
|
|
||||||
while (valueNamesPrint < arg->m_requiredValueCount) {
|
|
||||||
ss << "\nvalue " << (++valueNamesPrint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw Failure(ss.str());
|
|
||||||
}
|
}
|
||||||
|
stringstream ss(stringstream::in | stringstream::out);
|
||||||
|
ss << "Not all parameter for argument \"" << arg->name() << "\" ";
|
||||||
|
if (i) {
|
||||||
|
ss << " (" << (i + 1) << " occurrence) ";
|
||||||
|
}
|
||||||
|
ss << "provided. You have to provide the following parameter:";
|
||||||
|
size_t valueNamesPrint = 0;
|
||||||
|
for (const auto &name : arg->m_valueNames) {
|
||||||
|
ss << ' ' << name;
|
||||||
|
++valueNamesPrint;
|
||||||
|
}
|
||||||
|
if (arg->m_requiredValueCount != Argument::varValueCount) {
|
||||||
|
while (valueNamesPrint < arg->m_requiredValueCount) {
|
||||||
|
ss << "\nvalue " << (++valueNamesPrint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw Failure(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check contraints of sub arguments recursively
|
// check contraints of sub arguments recursively
|
||||||
|
|
Loading…
Reference in New Issue