From 09f91812819d89ea15edcce2785c60cf733b37d9 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 28 Jan 2018 00:38:05 +0100 Subject: [PATCH] Split operations from other top-level args in --help --- application/argumentparser.cpp | 34 +++++++++++++++++++++++++++++++--- tests/argumentparsertests.cpp | 11 ++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index 87b60ca..ba7bd9d 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -717,10 +717,38 @@ void ArgumentParser::printHelp(ostream &os) const } EscapeCodes::setStyle(os); if (!m_mainArgs.empty()) { - os << "Available arguments:"; + bool hasOperations = false; for (const Argument *arg : m_mainArgs) { - os << '\n'; - arg->printInfo(os); + if (arg->denotesOperation()) { + hasOperations = true; + break; + } + } + + // check whether operations are available + if (hasOperations) { + // split top-level operations and other configurations + os << "Available operations:"; + for (const Argument *arg : m_mainArgs) { + if (arg->denotesOperation()) { + os << '\n'; + arg->printInfo(os); + } + } + os << "\nAvailable top-level options:"; + for (const Argument *arg : m_mainArgs) { + if (!arg->denotesOperation()) { + os << '\n'; + arg->printInfo(os); + } + } + } else { + // just show all args if no operations are available + os << "Available arguments:"; + for (const Argument *arg : m_mainArgs) { + os << '\n'; + arg->printInfo(os); + } } } if (applicationUrl && *applicationUrl) { diff --git a/tests/argumentparsertests.cpp b/tests/argumentparsertests.cpp index b4ec2b9..ae518ad 100644 --- a/tests/argumentparsertests.cpp +++ b/tests/argumentparsertests.cpp @@ -679,15 +679,16 @@ void ArgumentParserTests::testHelp() const OutputCheck c("\e[1m" APP_NAME ", version " APP_VERSION "\n" "\e[0mLinked against: somelib, some other lib\n" "\n\e[0m" - "Available arguments:\n" - "\e[1m--help, -h\e[0m\n" - " shows this information\n" - " particularities: mandatory\n" - "\n" + "Available operations:\n" "\e[1mverbose, -v\e[0m\n" " be verbose\n" " example: actually not an operation\n" "\n" + "Available top-level options:\n" + "\e[1m--help, -h\e[0m\n" + " shows this information\n" + " particularities: mandatory\n" + "\n" "\e[1m--files, -f\e[0m\n" " specifies the path of the file(s) to be opened\n" " \e[1m--sub\e[0m\n"