Suppress "Available top-level options:" if none available

This commit is contained in:
Martchus 2019-09-14 20:52:35 +02:00
parent 5c098df8d7
commit 9cc6be4d4c
1 changed files with 13 additions and 7 deletions

View File

@ -814,10 +814,14 @@ void ArgumentParser::printHelp(ostream &os) const
}
if (!m_mainArgs.empty()) {
bool hasOperations = false;
bool hasOperations = false, hasTopLevelOptions = false;
for (const Argument *const arg : m_mainArgs) {
if (arg->denotesOperation()) {
hasOperations = true;
} else if (strcmp(arg->name(), "help")) {
hasTopLevelOptions = true;
}
if (hasOperations && hasTopLevelOptions) {
break;
}
}
@ -833,6 +837,7 @@ void ArgumentParser::printHelp(ostream &os) const
os << '\n';
arg->printInfo(os);
}
if (hasTopLevelOptions) {
os << "\nAvailable top-level options:";
for (const Argument *const arg : m_mainArgs) {
if (arg->denotesOperation() || arg->isDeprecated() || !strcmp(arg->name(), "help")) {
@ -841,6 +846,7 @@ void ArgumentParser::printHelp(ostream &os) const
os << '\n';
arg->printInfo(os);
}
}
} else {
// just show all args if no operations are available
os << "Available arguments:";