From 9cc6be4d4c1e962df932ab26c09ded93814b917b Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 14 Sep 2019 20:52:35 +0200 Subject: [PATCH] Suppress "Available top-level options:" if none available --- application/argumentparser.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 30d5967..788d5e1 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -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,13 +837,15 @@ void ArgumentParser::printHelp(ostream &os) const os << '\n'; arg->printInfo(os); } - os << "\nAvailable top-level options:"; - for (const Argument *const arg : m_mainArgs) { - if (arg->denotesOperation() || arg->isDeprecated() || !strcmp(arg->name(), "help")) { - continue; + if (hasTopLevelOptions) { + os << "\nAvailable top-level options:"; + for (const Argument *const arg : m_mainArgs) { + if (arg->denotesOperation() || arg->isDeprecated() || !strcmp(arg->name(), "help")) { + continue; + } + os << '\n'; + arg->printInfo(os); } - os << '\n'; - arg->printInfo(os); } } else { // just show all args if no operations are available